aggregating gradle multiproject test results using TestReport
From Example 4. Creating a unit test report for subprojects in the Gradle User Guide:
subprojects {
apply plugin: 'java'
// Disable the test report for the individual test task
test {
reports.html.enabled = false
}
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
reportOn subprojects*.test
}
Fully working sample is available from samples/testing/testReport
in the full Gradle distribution.
If using kotlin Gradle DSL
val testReport = tasks.register<TestReport>("testReport") {
destinationDir = file("$buildDir/reports/tests/test")
reportOn(subprojects.map { it.tasks.findByPath("test") })
subprojects {
tasks.withType<Test> {
useJUnitPlatform()
finalizedBy(testReport)
ignoreFailures = true
testLogging {
events("passed", "skipped", "failed")
}
}
}
And execute gradle testReport
. Source How to generate an aggregated test report for all Gradle subprojects
In addition to the subprojects
block and testReport
task suggested by @peter-niederwieser above, I would add another line to the build below those:
tasks('test').finalizedBy(testReport)
That way if you run gradle test
(or even gradle build
), the testReport
task will run after the subproject tests complete. Note that you have to use tasks('test')
rather than just test.finalizedBy(...)
because the test
task doesn't exist in the root project.