gpt4 book ai didi

Gradle Jacoco 报告覆盖率百分比与验证百分比不匹配

转载 作者:行者123 更新时间:2023-12-03 03:07:12 24 4
gpt4 key购买 nike

我们配置排除:

def coverageExcludes() {
return [
"com/ourcompany/*Config*",
"com/ourcompany/ServiceApplication*",
"com/ourcompany/Shutdown*",
"com/ourcompany/ShutdownConnector*",
"com/ourcompany/Tomcat*",
"com/ourcompany/TomcatCustomConnectorCustomizer*",
"com/ourcompany/endpoint/exception/**",
"com/ourcompany/endpoint/util/ObjectMapperBuilder*",
"com/ourcompany/framework/**",
"com/ourcompany/helper/ApiHelper*",
"com/ourcompany/helper/OffsetDateTimeDeserializer*",
"com/ourcompany/persistence/entity/**",
"com/ourcompany/persistence/exception/**",
"com/ourcompany/service/exception/ServiceException*",
"com/ourcompany/service/model/**",
"com/ourcompany/v2/**",
"com/ourcompany/v3/**"
]
}

jacocoTestReport 中使用它们:

jacocoTestReport {
reports {
xml {
enabled true
}
html {
enabled true
}
}
getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"));
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it,
exclude: coverageExcludes()
)
}))
for (Object c : classDirectories) {
System.out.println(c);
}
}
}

和排除工作:

enter image description here

然后我们尝试在验证任务中使用相同的排除项,将覆盖率失败阈值设置为 0.87,因为这是覆盖率报告中显示的内容:

jacocoTestCoverageVerification {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it,
exclude: coverageExcludes()
)
}))
for (Object c : classDirectories) {
System.out.println(c);
}
}
violationRules {
rule {
element = 'BUNDLE'
limit {
counter = 'INSTRUCTION'
value = 'COVEREDRATIO'
minimum = 0.87
}
}
}
}
check.dependsOn jacocoTestCoverageVerification

但这不起作用:

Execution failed for task ':settings:jacocoTestCoverageVerification'.

Rule violated for bundle settings: instructions covered ratio is 0.70, but expected minimum is 0.87

我们比较了两个任务中 classDirectories 的输出,它们完全匹配,排除列表中没有任何内容在 classDirectories 中。这意味着两个任务看到相同的类。

然而,验证任务得到的覆盖率答案与报告任务不同。

这很令人担忧,因为我们不知道哪个任务得到了正确答案。如果是报告任务,我们可以接受验证任务中较低的阈值,但如果我们真的只有 70% 的覆盖率,我们想知道这一点。

正如我们从文档中得知的那样,我们已将验证任务配置为以与报告任务生成的方式完全相同的方式分析覆盖率。

我们做错了什么?

(我们使用的是 Gradle 5.5.1,目前还不能升级,但如果我们能解决这个问题就会升级。)

最佳答案

您在jacocoTestReport 任务中配置ExecutionData

getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"));

但不在 jacocoTestCoverageVerification 任务中。

关于Gradle Jacoco 报告覆盖率百分比与验证百分比不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60438452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com