章节十六、10-TestNG报告和日志
一、在进行自动化的过程中,日志一般采用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基础开始。
欢迎关注,转载请注明来源。
章节十六、10-TestNG报告和日志的更多相关文章
- spring-boot-route(十六)使用logback生产日志文件
日志是一个系统非常重要的一部分,我们经常需要通过查看日志来定位问题,今天我们一起来学习一下Spring Boot的日志系统.有很多同学习惯性的在生产代码中使用System.out来输出日志,这是不推荐 ...
- 章节十六、1-TestNG简介
一.TestNG 介绍 1.TestNG 是一个来自 JUnit 和 NUnit 的测试框架,它具拥有更多的功能,提高了 执行的效率. 2.TestNG 是一个开源的自动化测试框架 去除了老框架的大部 ...
- 章节十六、3-TestNG方法和类注解
一.Test Suite(测试套件) 我们通常认为一个testcase就是一个测试方法,但是会有很多的testcase,所以我们不可能把所有的testcase放到同一个测试类中,假如需要测试的页面有1 ...
- 章节十六、5-TestNG高级功能--Part2
一.测试用例的依赖关系--->(dependsOnMethods = {"依赖方法名"}) 1.在实现自动化的过程中,有些测试用例必须在其它测试用例执行之后才能运行,两者之间 ...
- 章节十六、2-TestNG注解和断言
一.TestNG注解的testcease不是自上而下运行的,而是按照方法名的字母排序或数字的大小顺序运行的. 二.断言:判断返回的结果与我们的预期结果是否一致. 1.Assert.assertTrue ...
- 章节十六、4-TestNG高级功能--把测试方法分优先级、分组执行
一. 把测试方法分优先级执行----->(priority=索引) 1.新建一个testng方法 package testclasses; import org.testng.annotatio ...
- 章节十六、6-xml参数化and并行case
一.读取xml文件中参数 1.案例演示--->创建一个需要读取数据的类 package testclasses; import org.testng.annotations.Test; impo ...
- 章节十六、7-DataProviders
一.当我们的同一个test有多套数据需要进行测试,那么我们就需要用到-->DataProviders package testclasses1; import org.testng.annota ...
- 章节十六、8-ITestResult接口
一.ITestResult:该接口就像一个监听器,能够监听每个方法执行后的状态(是否成功)并将结果返回给我们. package testclasses1; import org.testng.anno ...
随机推荐
- Sqlserver2012 评估期已过问题
sql server 2012提示评估期已过的解决方法: 第一步:进入SQL2012配置工具中的安装中心. 第二步:再进入左侧维护选项界面,然后选择选择版本升级. 第三步:进入输入产品密钥界面,输入相 ...
- .net core 实现 api网关 进行 api版本控制
场景: 由一次大的项目改动引起的app端api不兼容问题,这时候就需要对api做版本控制了,权衡之后因为用户不多,选择了强更,没人想在已经写了8000行代码的单个svc文件中维护好几个版本的接口或者继 ...
- Kali-Linux-美化与优化
照理说,linux的桌面是不应当存在在这个世界上的,作为一个linux用户,一味捣鼓桌面显得hin-不专业.但是,虚拟机要用到,浏览器要用到--更何况,自己的老婆能不打扮一下么? update:201 ...
- SynchronousQueue队列程序的执行结果分析
public static void main(String[] args) throws Exception { /** * SynchronousQueue队列程序的执行结果分析 * Blocki ...
- 9407web常用符号
常用符号 转载自 http://www.fhdq.net/ ❤❥웃유♋☮✌☏☢☠✔☑♚▲♪✈✞÷↑↓◆◇⊙■□△▽¿─│♥❣♂♀☿Ⓐ✍✉☣☤✘☒♛▼♫⌘☪≍←→◈◎☉★☆⊿※¡━┃♡ღツ☼☁❅♒✎©® ...
- python 17 内置模块
目录 1. 序列化模块 1.1 json 模块 1.2 pickle 模块 2. os 模块 3. sys 模块 4. hashlib 加密.摘要 4.1 加密 4.2 加盐 4.3 文件一致性校验 ...
- alter add命令用来增加表的字段
alter add命令格式:alter table 表名 add字段 类型 其他; 例如,在表MyClass中添加了一个字段passtest,类型为int(4),默认值为0: mysql> al ...
- 互联网从此没有 BAT
根据 Wind 数据截止2019年8月30日,中国十大互联网上市公司排名中,百度排名第 6 位市值 365 亿美元,阿里巴巴排名第一市值高达 4499 亿美元,腾讯排名第二市值 3951 亿美元. 1 ...
- Educational Codeforces Round 43 E&976E. Well played! 贪心
传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...
- Codeforces Round #479 (Div. 3) B. Two-gram
原题代码:http://codeforces.com/contest/977/problem/B 题解:有n个字符组成的字符串,输出出现次数两个字符组合.例如第二组样例ZZ出现了两次. 方法:比较无脑 ...