How to aggregate test reports on test failures and still fail the build?


(Woody Wu) #1

how to ensure subprojects*.copy (used to copy xml test report files to root project buildDir) always run even there are test failures, and if with ignoreFailures set to true how to ensure the build is failed? ‘–continue’ does not solve the problem.


(Woody Wu) #2

add my code in root project build.gradle

subprojects {

apply plugin: ‘java’

test.ignoreFailures = true

test.doLast{

copy {

from ‘build/test-results’

into ‘…/build/xml-report’

include ‘**/*.xml’

}

} }


(Woody Wu) #3

issue is resolved as below:

subprojects {

apply plugin: ‘java’

task copyReport {

copy {

from ‘build/test-results’

into ‘…/build/xml-report’

include ‘**/*.xml’

}

} }

task testReport {

subprojects*.copyReport }

and then run “gradle clean build testReport --continue”


(Peter Niederwieser) #4

This solution has several problems. In particular, a task should never call another task. A better approach is to use a finalizer task. Something like:

subprojects {
    apply plugin: "java"
    task copyReport(type: Copy) {
        from "build/test-results"
          into "$rootDir/build/xml-report"
    }
    test.finalizedBy(copyReport)
}

PS: Please always wrap code snippets in HTML code blocks.