jacoco的Gradle构建控制台输出称';这比实际情况低%
我试图用jacoco做一个gradle构建,但是失败了,因为覆盖率低于“预期”。但是当我打开生成的HTML文件时,它实际上比我设置的最小值高 我试图排除更多的文件进行分析,但没有帮助jacoco的Gradle构建控制台输出称';这比实际情况低%,gradle,kotlin,code-coverage,jacoco,Gradle,Kotlin,Code Coverage,Jacoco,我试图用jacoco做一个gradle构建,但是失败了,因为覆盖率低于“预期”。但是当我打开生成的HTML文件时,它实际上比我设置的最小值高 我试图排除更多的文件进行分析,但没有帮助 jacoco { toolVersion = "0.8.4" // applyTo test } jacocoTestReport.dependsOn(test) // this just ensures it runs with for build, but not for non-build
jacoco {
toolVersion = "0.8.4"
// applyTo test
}
jacocoTestReport.dependsOn(test)
// this just ensures it runs with for build, but not for non-builds (like tests)
build {
finalizedBy jacocoTestReport
// this will do checks on the violations + fail build if there's too little coverage
finalizedBy jacocoTestCoverageVerification
}
jacocoTestReport {
reports {
csv.enabled false
xml.enabled false
html.enabled true
// setting the output location for html stuff
html.destination file("${buildDir}/reports/jacoco")
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [...files...])
}))
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
// % in decimal form for when build should fail
minimum = 0.75
}
}
}
}
我在构建中得到的结果是:指令覆盖率为0.74,但预期最小值为0.75
但正如你在书中看到的,这是80%。为什么会发生这种情况?类排除可能没有应用于JacoTestCoverage验证任务 您是否也尝试过在JacoCoTestCoverage验证任务中应用排除
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
// % in decimal form for when build should fail
minimum = 0.75
}
}
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [...files...])
}))
}
}
}
类似于:一个有趣的现象:所以我将min设置为0.99,看看是否有帮助。jacocoTestReport中显示覆盖率为0.79,但HTML文件显示覆盖率为80%。在JacoCoTestCoverage验证中,它表示覆盖率为0.8,但HTML文件表示覆盖率为79%(不排除文件)。在他们两人身上复制这一点使他们达成一致。。。谢谢,你的建议成功了!