My Gradle build does the following
- Runs the tests
- Opens a test report in the browser
- Opens a test coverage in the browser
- Verifies that test coverage is at least 80%
The relevant tasks in build.gradle are:
task testWithReports {
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
}
}
}
}
If I run testWithReports
and the jacocoTestCoverageVerification
subtask fails, the test reports are not opened. Is there a way to define these tasks which ensures that these reports are always opened?