I am posting updated answer on this topic. I am using Gradle 7.5.1.
TestReport task
In short I'm using following script to set up test aggregation form subprojects (based on @Peter's answer):
subprojects {
apply plugin: 'java'
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
testResults.from = subprojects*.test
}
Note that reportOn
method is "deprecated" or will be soon and replaced with testResults
, while at the same time testResults
is still incubating as of 7.5.1.
I got following warning in IDE
The TestReport.reportOn(Object...) method has been deprecated. This is scheduled to be removed in Gradle 8.0.
Hint: subproject*.test
is example of star dot notation in groovy that invokes test task on a list of subprojects. Equally would be invocation of subprojects.collect{it.test}
test-report-aggregation plugin
There is also alternative option for aggregating tests (Since Gradle 7.4). One can apply test-report-aggregation
plugin.
If your projects already apply java
plugin, this means they will come with jvm-test-suite
, all you have to do is apply the plugin.
plugins {
id 'test-report-aggregation'
}
Then you will be able to invoke test reports through testSuiteAggregateTestReport
task. Personally didn't use the plugin, but I think it makes sense to use it if you have multiple test suites configured with jvm-test-suite
.
Example project can be found in https://github.com/gradle-samples/Aggregating-test-results-using-a-standalone-utility-project-Groovy