<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<excludes>
<!-- excludes 配置要跳过单元测试的类,一般是实体类或Mybatis Mapper类 -->
<exclude>**/mapper/*</exclude>
<exclude>**/model/*</exclude>
<exclude>**/entity/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 在 pom.xml 的 project 根元素下建立 reporting 元素 -->
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
$ mvn clean test
如果要使失败的测试不影响测试报告的生成,使用
$ mvn clean test -Dmaven.test.failure.ignore=true
生成的测试报告位于 /target/site/jacoco
目录下