loading...
Cover image for How to generate an aggregated test report for all Gradle subprojects

How to generate an aggregated test report for all Gradle subprojects

jakub_zalas profile image Jakub Zalas Updated on ・1 min read

When using Gradle's multi-project builds, test reports are generated separately in each build directory of every sub-project.

To make my CI server's life easier I often like to aggregate reports in a single build directory:

// build.gradle.kts

plugins {
    base
    kotlin("jvm") version "1.3.72" apply false
}

allprojects {
    group = "com.kaffeinelabs"
    version = "1.0.0-SNAPSHOT"
}

val testReport = tasks.register<TestReport>("testReport") {
    destinationDir = file("$buildDir/reports/tests/test")
    reportOn(subprojects.mapNotNull {
        it.tasks.findByPath("test") 
    })

subprojects {
    tasks.withType<Test> {
        useJUnitPlatform()
        finalizedBy(testReport)
        testLogging {
            events("passed", "skipped", "failed")
        }
    }
}

If you're interested in how to aggregate code coverage reports, I covered it in another article:

Posted on by:

jakub_zalas profile

Jakub Zalas

@jakub_zalas

Quality focussed software engineer, architect, and trainer. Friends call me Kuba.

Discussion

markdown guide