Jacoco Gradle 中的最小代码覆盖阈值 [英] Minimum code coverage threshold in Jacoco Gradle

查看:37
本文介绍了Jacoco Gradle 中的最小代码覆盖阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如果不满足,我希望构建失败.

解决方案

该功能现已可用.您只需要应用 Gradle JaCoCo 插件并像这样定义覆盖验证:

应用插件:'jacoco'jacocoTestCoverageVerification {违反规则{规则 {限制 {最小值 = 0.7}}}}//在构建期间运行覆盖率验证(并在适当时失败)check.dependsOn jacocoTestCoverageVerification

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

有关您可以添加的检查类型的更多信息,请参阅文档插件.

How can I set the minimum code coverage in Jacoco Gradle?

I want the build to fail if it is not met.

解决方案

The feature is now available. You simply need to apply the Gradle JaCoCo plugin and define coverage verification like this:

apply plugin: 'jacoco'

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

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

The last line is very important as your build would otherwise not fail unless you explicitly run the jacocoTestCoverageVerification task.

More information on the kind of checks you may add is in the documentation of the plugin.

这篇关于Jacoco Gradle 中的最小代码覆盖阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆