Maven + testNG + reportNG + Jacoco
一、maven pom配置
testNG依赖
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
reportNG 依赖
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
com.google.inject 这个也要依赖上,否则会报错
Jacoco 依赖
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase> // 测试期间执行插件
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
maven 插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<!-- 加入编码设置,否则生成的报告会中文乱码 -->
<argLine> @{
argLine

本文介绍了如何在Maven项目中结合testNG、reportNG和JaCoCo进行代码覆盖率测试。首先,详细列出了在pom.xml中配置testNG、reportNG和JaCoCo的依赖以及maven插件的步骤。接着,通过创建maven工程并编写testNG.xml文件,展示了如何设置工程目录和编写测试类。最后,讲解了如何执行测试命令生成JaCoCo报告,并指出了查看报告的位置。
最低0.47元/天 解锁文章
1787

被折叠的 条评论
为什么被折叠?



