章节十六、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 ...
随机推荐
- CSS布局:元素垂直居中
CSS布局之元素垂直居中 本文将依次介绍在不同条件下实现垂直居中的多种方法及简单原理 Tip:下文中说的适用场景只是举了几个简单的例子方便读者理解.实际应用场景太复杂,生搬硬套容易出错.最重要的是掌握 ...
- Leetcode之深度优先搜索(DFS)专题-733. 图像渲染(Flood Fill)
Leetcode之深度优先搜索(DFS)专题-733. 图像渲染(Flood Fill) 深度优先搜索的解题详细介绍,点击 有一幅以二维整数数组表示的图画,每一个整数表示该图画的像素值大小,数值在 0 ...
- [工具使用]-利用latex管理创建自己的ACM模板
从很早入坑ACM开始,便和各种算法的模板打着交道,虽然kaungbin的模板已经足够强大,但是自己在平常做题中也逐渐有着自己的一些模板,也有一些kuangbin模板中没有的更快的板子,虽然不确定时候以 ...
- Python数据类型详解——元组
Python数据类型详解--元组 有时候我们的列表数据不想被别人修改时该怎么办? 此时,就可以使用元组来存放,元祖又称为只读列表,不能修改 定义方式:与列表类似,将列表的[]换成()即可. 特性: 1 ...
- .net中DES加密算法研究
/// <summary> /// DES加密算法 /// </summary> /// <param name="toEncrypt">要加密 ...
- 【Edu 67】 补题记录
CF1187D. Subarray Sorting 想要把一个数x换到前面,x一定是小一点的值.由于B串是固定的,A串可调整,我们可以遍历B数组,对于B[i],找到对于在A数组的位子pos,判断1-p ...
- P1963 [NOI2009]变换序列 倒叙跑匈牙利算法
题意 构造一个字典序最小的序列T,使得 Dis(i, Ti) = di,其中i是从0开始的,Dis(x,y)=min{∣x−y∣,N−∣x−y∣} ,di由题目给定. 思路 二分图匹配,把左边的看成i ...
- CodeForces 1042 F Leaf Sets 贪心
Leaf Sets 题意:给你一棵树,树上有n个点,只有一条边的点叫做叶子,现在要求把所有的叶子分组,每个组内的所有叶子的距离都不能大于k. 题解: 我们可以随意找一个不是叶子的节点当做这颗树的根节点 ...
- poj 3259 Wormholes(bellman-ford判断负环)
题目链接:http://poj.org/problem?id=3259 题目就是问你能否回到原点而且时间还倒回去了.题目中有些路中有单向的虫洞能让时间回到过去 所以只要将虫洞这条边的权值赋为负然后再判 ...
- js中的兼容问题汇总
在使用js的过程中,往往会发现关于IE浏览器的兼容问题,当然微软现在自己也打算抛弃IE,推出了edge浏览器,对于前端来说是个好消息. 但IE的用户占比仍然不容小觑,因此这里整理下常见的几个兼容问题附 ...