TestReport not generated if one of executed tests fails

Hi, I am trying to use the TestReport. If I execute the task it starts with running all the tests and then tests on one of the project fails Gradle aborts the build with failure message. The TestReport itself is never executed in such scenario.

Is it the expected behaviour? I was under impression that after all tests were executed TestReport should generate a consolidated tests report for all projects.

I tried the two following approaches of executing it:

task testReport(type: TestReport) {
    subprojects {
        reportOn { tasks.withType(Test) }
    }
    destinationDir = file("${buildDir}/reports/allTests")
}
task testReport2(type: TestReport) {
  destinationDir = file("$buildDir/reports/allTests")
  // Include the results from the 'test' task in all subprojects
  println("$buildDir")
  reportOn subprojects*.test
}

Please advice how I can fix it.

3 Likes

Hi Sergey,

Sorry for the delay in responding.

Unfortunately you have found one of the areas that are not as simple to use as we would like. Basically, the way you have configured TestReport automatically sets up a dependsOn relationship, which is probably not what you actually want since it will bail once the build fails ( as it will by default when a test fails).

There are a number of ways of dealing with this (including using the --continue flag and Test.ignoreFailures), but probably the simplest approach is to avoid setting up the dependsOn relationship (by reporting on the test output directories rather than the test task themselves) and then setting up a finalizedBy relationship instead, like this:

evaluationDependsOnChildren()
task testReport(type: TestReport) {
        destinationDir = file("$buildDir/reports/allTests")
        reportOn subprojects*.test.binResultsDir
}
subprojects {
    test.finalizedBy(testReport)
}

now run your tests using ‘gradle test’ and you should get the behaviour you want.

2 Likes

Worked like a charm

1 Like

After I added the configuration proposed above I got the test reports working, but I observed unexpected side effects: 1) order of execution of subprojects changed

  1. one of subprojects started to produce incorrect artifact. This project includes code generation and some other manipulations, but it was totally unexpected that adding test reports will break it.

Can you advise if it is a bug and how I can investigate the problem?