我想让jacoco工作,所以它报告我的 我的集成测试的代码覆盖率。目前我有这个 设置
parent.pom
-- module1
-- module2
-- module3
-- module4
-- report
模块1到3包含我的源代码,而模块4包含一个 客户端,运行集成测试。
parent.pom包含jacoco-plugin:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>prepare-unit-test-agent</id>
<phase>generate-test-sources</phase>
<configuration>
<append>true</append>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>prepare-it-test-agent</id>
<phase>pre-integration-test </phase>
<configuration>
<propertyName>failsafeArgLine</propertyName>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<append>true</append>
</configuration>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>`
报告pom:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>it-report</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
<dataFileInclude>**/jacoco-it.exec</dataFileInclude>
</dataFileIncludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-overall</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
在我的报告模块中,所有其他模块都作为依赖项导入 with scope = compile。
现在,生成的Coverage只显示测试覆盖的内容 放在模块1中。因为逻辑是这样的:模块3 =接口模块2 =接口模块的实现1 =实体
奇怪的是,模块2和3的代码没有显示为 覆盖。所有测试都调用模块3中的方法。
仅供参考:来源是Java,测试是常规的