Aggregate test results created by multiple test tasks


(Benjamin Muschko) #1

Hi,

I have a project that contains test classes written with different testing frameworks (JUnit, TestNG, Spock). What’s the best way of aggregating the test reports generated by each individual test task into one using Gradle 1.4? Currently, I am using the internal API class DefaultTestReport but was wondering if there is a way to do this with a class of the public API. This is how the relevant parts of my build script look like:

import org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport
import org.gradle.api.internal.tasks.testing.junit.result.AggregateTestResultsProvider
  task testNG(type: Test) {
   useTestNG()
}
   test.dependsOn testNG
   test {
   doLast {
      def reporter = new DefaultTestReport()
      def binTestDirs = files(test.binResultsDir, testNG.binResultsDir)
       reporter.generateReport(new AggregateTestResultsProvider(binTestDirs), test.testReportDir)
   }
}

(Benjamin Muschko) #2

Perfect, that’s exactly what I was looking for.


(Tobias Schulte) #3

I have the problem, that the aggregate report is only generated, if all tests succeed.

task allTests(type: TestReport) {

doFirst {

gradle.startParameter.continueOnFailure = true

}

destinationDir = file("$buildDir/reports/allTests")

// Include the results from the ‘test’ task in all subprojects

project.subprojects {

tasks.withType(Test) {

reportOn it

}

}

}

To get the report, when there are failing tests, I have to execute

./gradlew allTests

followed by

./gradlew allTests -xtest

Only at the second invocation, the report is generated.


(Peter Niederwieser) #4

Try the new TestReport task.