TestNG之使用ReportNG生成测试报告
TestNG使用ReportNG生成测试报告会更加美观。
- 依赖包
1 <!--testNG报告依赖包--> 2 <dependency> 3 <groupId>org.testng</groupId> 4 <artifactId>testng</artifactId> 5 <version>6.14.3</version> 6 <scope>test</scope> 7 </dependency> 8 <dependency> 9 <groupId>org.uncommons</groupId> 10 <artifactId>reportng</artifactId> 11 <version>1.1.4</version> 12 <scope>test</scope> 13 </dependency> 14 <dependency> 15 <groupId>com.google.inject</groupId> 16 <artifactId>guice</artifactId> 17 <version>4.2.2</version> 18 </dependency>
<!-- 生产html报告使用,过高版本会导致变量不能替换--> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency>
build配置:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <!-- <version>2.22.1</version>--> <configuration> <!--<testFailureIgnore>true</testFailureIgnore>--> <forkMode>never</forkMode> <argLine>-Dfile.encoding=UTF-8</argLine> <suiteXmlFiles> <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> </suiteXmlFiles> <properties> <property> <name>usedefaultlisteners</name> <value>true</value> </property> <property> <name>listener</name> <value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value> </property> </properties> <workingDirectory>target/</workingDirectory> <forkMode>always</forkMode> <!-- 解决报告中中文乱码 --> <argLine>-Dfile.encoding=UTF-8</argLine> </configuration> </plugin> </plugins>
- 构建配置
监听名:org.uncommons.reportng.HTMLReporter
- TestNG.xml配置
<suite> ... <listeners> <!--testng的XML配置文件中添加这些内容--> <listener class-name="org.uncommons.reportng.HTMLReporter"/> <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/> </listeners> </suite>
- 报告样式举例
./test-output/html/index.html