我有一个安静的api,集成测试用例的工作流程是我们构建项目 - >然后在预定义的端口上使用maven启动一个tomcat - >在该tomcat实例上部署构建的war,然后maven运行与该war相关的集成测试用例。只有在单元和集成测试用例通过时,构建才会成功。我想为集成以及单元测试用例生成代码覆盖率报告。虽然Jacoco正在为单元测试用例正确生成报告,但它没有为集成测试用例生成正确的报告。与所有文件夹一样,覆盖率为零。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<executions>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${basedir}/target/jacoco-unit.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${basedir}/target/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<includes>
</includes>
<dataFile>${basedir}/target/jacoco-it.exec</dataFile>
<outputDirectory>${basedir}/target/site/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
在故障安全插件上:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
<argLine>${failsafeArgLine}</argLine>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>