java - 如果新代码低于覆盖阈值,如何让构建失败?

标签 java sonarqube automated-tests code-coverage jacoco

是否有任何 Java 测试框架(最好是 Jacoco 和/或 Sonar)可以让代码覆盖率较差的团队原谅现有的代码库,但要求新代码高于阈值(直到他们能够获得所有覆盖了旧代码!)

最佳答案

您可以将构建插件添加到您的 pom.xml 中。此操作正在进行至少 80% 的线路覆盖率检查。请参阅Jacoco doc了解更多信息。

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.0</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jacoco-site</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jacoco-check</id>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <rule>
                                <element>BUNDLE</element>
                                <limits>
                                    <limit>
                                        <counter>LINE</counter>
                                        <value>COVEREDRATIO</value>
                                        <minimum>0.80</minimum>
                                    </limit>
                                </limits>
                            </rule>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

关于java - 如果新代码低于覆盖阈值,如何让构建失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47063528/

相关文章:

java - Sonar Qube 5.3 : Configure number of lines of source code displayed in Component Viewer

java - 如何将列表/数组作为参数传递给 JSystem 测试

java - 如何用Java编写惰性删除二叉搜索树的findMinimum

java - 带有变量的Android TextView id?

java - SonarQube 服务器日志显示超出了 GC 开销限制并且 TERM 被捕获正在关闭

selenium - 导出 WebDriver 代码 - Selenium IDE 与 Selenium Builder

python - 如何使用 selenium 2 检查网页上是否存在某些文本?

java - 内部类/接口(interface)中定义的泛型类型是否绑定(bind)到外部类泛型类型定义?

java - 在 jar 中包含库

import - 无法在 Eclipse 中导入 PMD 规则集