问题:如何配置 jacoco maven 插件以显示相对于自定义包的覆盖率报告?(而不是默认的:它正在执行的类的包)。
项目结构:
testprj
|
+ -- pom.xml // parent pom
|
+ -- starter // Aggregates (as dependencies) all other modules
| +
| |
| + /src/main/java/com/my/prj/testprj/starter/MainApplication.java // Springboot starter cls
| |
| + /src/test/java/com/my/prj/testprj/starter/ProjectIT.java // Integration tests
| |
| + -- pom.xml
|
+ -- core // acts as a controller
| +
| |
| + ...
| |
| + -- pom.xml
|
+ -- dbmock
| +
| |
| + ...
| |
| + -- pom.xml
|
+ -- gateway // REST endpoint
| +
| |
| + ...
| |
| + -- pom.xml
|
+ target/coverage/jacoco-it/jacoco-it.exec
|
+ ...
|
+ index.html // Jacoco Coverage Report
雅可可配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<propertyName>jacoco.agent.it.arg</propertyName>
<destFile>${session.executionRootDirectory}/target/coverage/jacoco-it/jacoco-it.exec</destFile>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<dataFile>${session.executionRootDirectory}/target/coverage/jacoco-it/jacoco-it.exec</dataFile>
<outputDirectory>${session.executionRootDirectory}/target/coverage/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
故障安全配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>${jacoco.agent.it.arg}</argLine>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
评论 :
1)我试图通过在多模块环境中通过从一个中央模块运行所有测试来超越多模块环境中不支持的聚合功能,该中心模块聚合了类路径中的所有其他模块并使用相同的包前缀其中com/my/prj/testprj/
2)问题:显示com/my/prj/testprj/starter包(包含测试类的包)的覆盖率报告。我想显示相对于com/my/prj/testprj/的覆盖率
3) IntelliJIdea IDE 通过让我指定记录覆盖率数据的包来轻松支持这一点(使用 Jacoco),请参见下文: