Maven的Java 8项目代码覆盖率

5

我希望为我的Java 8 Maven项目创建一个代码覆盖率报告。我使用Cobertura遇到了问题,因为它无法处理Java 8的语法。 有人熟悉其他解决方法吗?是否有其他Maven插件可供使用?

1个回答

5

使用适用于Java 8的JaCoCo

这是我pom文件中的插件XML:

<build>
...
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.5.201505241946</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>

        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
<rules><!-- implementation is needed only for Maven 2 -->
    <rule implementation="org.jacoco.maven.RuleConfiguration">
        <element>BUNDLE</element>
        <limits><!-- implementation is needed only for Maven 2 -->
            <limit implementation="org.jacoco.report.check.Limit">
                <counter>COMPLEXITY</counter>
                <value>COVEREDRATIO</value>
                <minimum>0.60</minimum>
            </limit>
        </limits>
    </rule>
</rules>
</configuration>
        </execution>
    </executions>
</plugin>
...
</build>

此外,它还与Jenkins等持续集成系统良好集成。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接