(003)maven项目使用jacoco测试单元覆盖率
直奔主题,在项目的pom.xml中配置插件:
<!-- 覆盖率 -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
运行:
mvn test
查看覆盖率:项目/target/site/jacoco/index.html,双击打开,点击每一条可逐级进入。