我们配置了排除:
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/**"
]
}
Run Code Online (Sandbox Code Playgroud)
将它们用于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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
并且排除工作:
然后我们尝试在验证任务中使用相同的排除,并将覆盖率失败阈值设置为 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
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
任务“:settings:jacocoTestCoverageVerification”执行失败。
捆绑设置违反规则:指令覆盖率为 0.70,但预期最小值为 0.87
我们比较了两个任务中的输出classDirectories,它们完全匹配,并且排除列表中没有任何内容classDirectories。这意味着这两个任务看到相同的类。
然而,验证任务在覆盖范围上得到的答案与报告任务不同。
这是令人担忧的,因为我们不知道哪个任务得到了正确的答案。如果是报告任务,我们可以接受验证任务中较低的阈值,但如果我们真的只有 70% 的覆盖率,我们想知道这一点。
据我们从文档中可以看出,我们已将验证任务配置为以与报告任务生成完全相同的方式分析覆盖率。
我们做错了什么?
(我们使用的是 Gradle 5.5.1,目前还无法升级,但如果我们能解决这个问题,我们就会升级。)
ExecutionData您在jacocoTestReport任务中配置
Run Code Online (Sandbox Code Playgroud)getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"));
但不在jacocoTestCoverageVerification任务中。
| 归档时间: |
|
| 查看次数: |
1880 次 |
| 最近记录: |