I have a project structure that looks like the below. I want to use the TestReport functionality in Gradle to aggregate all the test results to a single directory. Then I can access all the test results through a single index.html file for ALL subprojects. How can I accomplish this?
.
|--ProjectA
|--src/test/...
|--build
|--reports
|--tests
|--index.html (testresults)
|--..
|--..
|--ProjectB
|--src/test/...
|--build
|--reports
|--tests
|--index.html (testresults)
|--..
|--..
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With