1、添加pom文件,加入jacoco-maven-plugin
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.7.5.201505241946</version>
<scope>test</scope>
</dependency>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>prepare</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
2、确保所有的单元测试都是通过的。
3、mvn clean test
mvn跑下test,可先在本地看看单测覆盖率效果:
测试执行完成后,可在各模块的target/jacoco目录下看到index.html, 右键 index.html在浏览器中打开,能看到覆盖率数据,说明jacoco接入OK。