Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aggregating gradle multiproject test results using TestReport

Tags:

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)
            |--..
            |--..
like image 786
n4rzul Avatar asked Jun 04 '13 15:06

n4rzul


2 Answers

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.

like image 97
Peter Niederwieser Avatar answered Sep 17 '22 16:09

Peter Niederwieser


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.

like image 21
kousen Avatar answered Sep 19 '22 16:09

kousen