我无法让 Cobertura 插件在 Maven 中运行集成测试。我找到的最接近这个问题的答案是 http://jira.codehaus.org/browse/MCOBERTURA-86 .但是,该问题仍然是一个 Unresolved 错误。我尝试了 Stevo 于 09 年 3 月 3 日建议的配置,但没有奏效。
我的POM
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura-integration</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
顺便说一下,这与 Stevo 提供的配置片段完全相同。
最佳答案
在我看来, cobertura maven 插件有两大缺点。它有 没有报告只有目标 ,所有单元测试将再次在surefire旁边运行。它为单元测试创建代码覆盖率 只要 。
我正在使用 JaCoCo Maven 插件现在。 JaCoCo 重用万无一失和/或故障安全报告 从单元和/或集成测试创建代码覆盖率。此外,JaCoCo 有一个 Jenkins 集成良好 .下面是一个例子,其中 JaCoCo 使用了surefire 单元测试和故障安全集成测试。
<build>
<plugins>
<!-- Unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
<!-- Integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!--
The JaCoCo plugin generates a report about the test coverage. In contrast to the cobertura plugin
JaCoCo can be configured to generate code coverage for integration tests. Another advantage of JaCoCo
is that it reports only, cobertura executes all unit tests again (beside the surefire plugin).
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<execution>
<id>jacoco-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules />
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
关于maven-2 - 使用 Cobertura Maven 插件运行集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2188192/