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

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

问题描述

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

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

如果构建失败,我希望构建失败。

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

推荐答案

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

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

最后一行非常重要,因为除非您明确运行 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天全站免登陆