maven-2 - 使用 Cobertura Maven 插件运行集成测试

标签 maven-2 integration-testing cobertura

我无法让 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/

相关文章:

java - 有没有人使用本地 Maven 存储库中的 SnakeYAML 成功加载 YAML 文件?

java - 使用不同的 Spring 属性进行集成测试

java - 无法在 Play Framework 测试中从匿名回调内部传递异常

cobertura - Cobertura排除与忽略

java - 在 Maven 构建的 EAR 中绑定(bind)文件

java - 运行 mvn exec :java from a remote directory not containing the pom. xml

javascript - Pact:使用相同端点编写不同的交互

c# - xUnit - deps.json 不是为 .NetCore 3.1 [Api.deps.json' 中的集成测试创建的。该文件是功能测试正常运行所必需的。]

java - 为什么我的 Sonar 包名称中包含 "src/main/java"?

python - 无法在 azure 管道中发布代码覆盖率