一、在进行自动化的过程中,日志一般采用log4j 2进行日志记录,但TestNG自己本身也带有日志记录功能(reporter),它的好处在于日志中记录的内容都是testng自动生成的。

 package testclasses1;

 import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterClass; public class TestNG_ReportsAndLogs { @BeforeClass
public void setUp() {
// 需要传递2参数(String类型,Boolean)(需要打印的log信息,是否打印在控制台上true or false)
Reporter.log("TestNG_ReportsAndLogs -> 在class开始运行之前运行",true);
} @AfterClass
public void cleanUp() {
Reporter.log("TestNG_ReportsAndLogs -> 在class开始运行之后运行",true);
} @BeforeMethod
public void beforeMethod() {
Reporter.log("TestNG_ReportsAndLogs -> 在test方法开始运行之前运行",true);
} @AfterMethod
public void afterMethod() {
Reporter.log("TestNG_ReportsAndLogs -> 在test方法开始运行之后运行",true);
} @Test
public void testMethod1() {
Reporter.log("TestNG_ReportsAndLogs -> testMethod1",true);
} @Test
public void testMethod2() {
Reporter.log("TestNG_ReportsAndLogs -> testMethod2",true);
Assert.assertTrue(false);
} // 让testMethod3依赖testMethod2
@Test(dependsOnMethods= {"testMethod2"})
public void testMethod3() {
Reporter.log("TestNG_ReportsAndLogs -> testMethod3",true);
}
}

运行截图:

二、如何查看reporter生成的HTML报告

 package testclasses1;

 import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterClass; public class TestNG_ReportsAndLogs { @BeforeClass
public void setUp() {
// 需要传递2参数(String类型,Boolean)(需要打印的log信息,是否打印在控制台上true or false)
Reporter.log("TestNG_ReportsAndLogs -> 在class开始运行之前运行",true);
} @AfterClass
public void cleanUp() {
Reporter.log("TestNG_ReportsAndLogs -> 在class开始运行之后运行",true);
} @BeforeMethod
public void beforeMethod() {
Reporter.log("TestNG_ReportsAndLogs -> 在test方法开始运行之前运行",true);
} @AfterMethod
public void afterMethod() {
Reporter.log("TestNG_ReportsAndLogs -> 在test方法开始运行之后运行",true);
} @Test
public void testMethod1() {
Reporter.log("TestNG_ReportsAndLogs -> testMethod1",true);
} @Test
public void testMethod2() {
Reporter.log("TestNG_ReportsAndLogs -> testMethod2",true);
Assert.assertTrue(false);
} // 让testMethod3依赖testMethod2
@Test(dependsOnMethods= {"testMethod2"})
public void testMethod3() {
Reporter.log("TestNG_ReportsAndLogs -> testMethod3",true);
}
}

1、首先需要配置xml文件,然后运行

 <!-- 没有此行配置运行时可能会报错 -->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Regression TestSuite">
<test name="Application Test">
<classes>
<class name="testclasses1.TestNG_ReportsAndLogs"></class>
</classes>
</test>
</suite>

2、运行结果为:

3、xml配置文件运行后会出现如图所示的文件夹

4、HTML形式报告展示(截图有限,仅展示一部分)

如果有不明白的小伙伴可以加群“555191854”问我,群里都是软件行业的小伙伴相互一起学习。

内容具有连惯性,未标注的地方可以看前面的博客,这是一整套关于ava+selenium自动化的内容,从java基础开始。

欢迎关注,转载请注明来源。

最新文章

  1. [.Net] 手把手带你将自己打造的类库丢到 NuGet 上
  2. js修改不了input的值
  3. [转]基于AWS的自动化部署实践
  4. Win10 UWP应用发布流程
  5. opencv的学习笔记4
  6. dojo.hitch 原理
  7. stream_iterator、ostream_iterator 使用初探
  8. angular checkbox required
  9. jquery-plugin-biggerLink,highLight-层加亮_andy 阳光生活_百度空间
  10. struts2 taglib struts标签学习整理中
  11. Swift - 使用arc4random()、arc4random_uniform()取得随机数
  12. 【个人笔记】《知了堂》前端mySql基础
  13. a链接在新窗口打开
  14. 20道Java面试必考题
  15. [SDOI2008]Sue的小球
  16. String Byte 互转
  17. android 图片上传图片 报Socket: Broken pipe
  18. 【转】RPC介绍
  19. ArcGisServer根据最大最小坐标换算瓦片行列号【转】
  20. QtGUI Module&#39;s Classes

热门文章

  1. Linux配置部署_新手向(二)——Nginx安装与配置
  2. ceph存储基础概念
  3. 如何美观地打印 Python 对象?这个标准库可以简单实现
  4. 史上最全面的SignalR系列教程-6、SignalR 实现聊天室
  5. HandlerMethodArgumentResolver(三):基于消息转换器的参数处理器【享学Spring MVC】
  6. Spark的安装及配置
  7. go-web程序的热更新
  8. yield 实现range()函数
  9. poj2396 Budget 上下界可行流
  10. 牛客练习赛38 E 出题人的数组 2018ccpc桂林A题 贪心