我的Gradle版本执行以下操作
build.gradle
中的相关任务是:
task testWithReports {
description "Runs all tests, open the coverage and test reports in a browser, and verify the test coverage rules"
dependsOn 'clean'
dependsOn 'test'
dependsOn 'jacocoTestReport'
dependsOn 'showCoverage'
dependsOn 'showTestResults'
dependsOn 'jacocoTestCoverageVerification'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}
task showCoverage {
doLast {
desktop.browse "file:///${buildDir}/jacocoHtml/index.html".toURI()
}
}
task showTestResults {
doLast {
desktop.browse "file:///${buildDir}/junitHtml/index.html".toURI()
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.8
}
}
}
}
如果我运行testWithReports
并且jacocoTestCoverageVerification
子任务失败,则不会打开测试报告。有没有一种方法可以定义这些任务,以确保始终打开这些报告?