问题:如何配置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
Jacoco配置:
<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)我尝试通过在多模块环境中jacoco maven插件不支持的聚合功能,通过从集中路径中聚合所有其他模块的中央模块运行所有测试并使用相同的包所有这些中的前缀 com / my / prj / testprj /
2)问题:显示 com / my / prj / testprj / starter 包(包含测试类的包)的覆盖率报告。我想显示相对于 com / my / prj / testprj /
的报道3)IntelliJIdea IDE通过让我指定要记录覆盖率数据的包,轻松支持这个(使用Jacoco),请参阅下文: