我的maven项目目录结构如下:
parent
-child
-src/java
-src/test <!-- unit tests -->
-pom.xml
-integration_test
-src/test
-pom.xml
-report
-pom.xml
-pom.xml
由于集成测试和源代码位于不同的模块中,因此我使用了Jacoco report-aggragate(报告模块)。
父pom.xml
<profile>
<id>codecoverage-it</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
报告模块pom.xml
<dependencies>
<dependency>
<groupId>###</groupId>
<artifactId>child</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>###</groupId>
<artifactId>integration_test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>overage-aggregate</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
单元测试代码覆盖率报告正确显示,但是对于集成测试,即使执行了测试,代码覆盖率也被指定为0