DEV Community

Cover image for How to generate an aggregated test report for all Gradle subprojects
Jakub Zalas
Jakub Zalas

Posted on • Updated on

How to generate an aggregated test report for all Gradle subprojects

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:

Discussion (1)

Collapse
velbur profile image
Velbur • Edited on

Thank you. Great article! But looks like no reports if tests are failed...