jacocoTestCoverageVerification

jacocoTestCoverageVerification

如何在Jacoco Gradle中设置最小代码覆盖率?

如果不满足要求,我希望构建失败。

最佳答案

该功能现在可用。您只需要应用Gradle JaCoCo插件并定义覆盖范围验证,如下所示:

apply plugin: 'jacoco'

jacocoTestCoverageVerification {
    violationRules {
        rule {
            limit {
                minimum = 0.7
            }
        }
    }
}

// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification

最后一行非常重要,因为除非您明确运行jacocoTestCoverageVerification任务,否则构建不会失败。

您可以添加的支票种类的更多信息在documentation of the plugin中。

10-06 03:22