文章目录
1、POM文件配置
pom文件配置jacoco插件
<!-- 生成JaCoCo覆盖率数据插件 -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
2、编写单元测试
编写单元测试用例可以参考以下内容
JUNIT5+Mockito单元测试
使用testMe自动生成单元测试用例
3、执行单元测试
执行 mvn clean test
执行 mvn jacoco:report
也可以在IDEA操作
4、查看单元测试覆盖率
查看文件 target/site/jacoco/index.html
