reportOn replacement for gradle 8

This old post was helpful:

However, reportOn is deprecated, and the replacement is not clear.

This is a snippet of my top-level build.gradle:

task allTestsReport(type: TestReport) {
destinationDirectory = file("$buildDir/reports/allTests")
reportOn subprojects*.test
doFirst {
println “Consolidating tests in $buildDir/reports/allTests”
project.file("$buildDir/reports/allTests").mkdirs()
}
}

At build time under gradle 7.4, I get:

The TestReport.reportOn(Object…) method has been deprecated. This is scheduled to be removed in Gradle 8.0. Please use the testResults method instead. See TestReport - Gradle DSL Version 7.4 for more details.

The documentation is not clear though. I can’t just swap reportOn out for testResults, and there seems to be more involved given the section the error links to.

What should change to be prepared for gradle 8?

The DSL it links to and also the JavaDoc are pretty clear, aren’t they?
They say

use TestReport.getTestResults() and invoke ConfigurableFileCollection.from(java.lang.Object[]) instead, passing references to AbstractTestTadksk.getBinaryResultsDirectory() as arguments.

So basically it should be something like

testResults.from(subprojects*.test*.binaryResultsDirectory

But actually you might be interested in simply using the Test Report Aggregation Plugin:
https://docs.gradle.org/7.4/release-notes.html#aggregation-tests
https://docs.gradle.org/7.4/userguide/test_report_aggregation_plugin.html