Generate Jacoco report for integration tests

1.1k Views Asked by At

I've created a new test suite called integrationTest using the jvm-test-suite plugin.

Now I want to generate a jacoco report just for the integration tests.

I create a new gradle task like this:

tasks.create<JacocoReport>("jacocoIntegrationTestReport") {
    group = "verification"
    description = "Generates code coverage report for the integrationTest task."

    executionData.setFrom(fileTree(buildDir).include("/jacoco/integrationTest.exec"))

    reports {
        xml.required.set(true)
        html.required.set(true)
    }
}

But the generated HTML/XML report is empty. I have run the integration tests before executing the task and the file integrationTest.exec exists.

Thanks

1

There are 1 best solutions below

0
On

It seems the important part of the new JaCoCo report task configuration is to wire the execution data via the integrationTest task instead of the exec-file path. The official docs (see last example here) also imply that the source set must be wired as well.

Here is the full build script (Gradle 7.6) that produces a report with command:

./gradlew :app:integrationTest :app:jacocoIntegrationTestReport

// build.gradle.kts

plugins {
    application
    jacoco
}

repositories {
    mavenCentral()
}

testing {
    suites {
        val integrationTest by creating(JvmTestSuite::class) {
            dependencies {
                implementation(project(":app"))
            }
        }
    }
}

tasks.register<JacocoReport>("jacocoIntegrationTestReport") {
    executionData(tasks.named("integrationTest").get())
    sourceSets(sourceSets["integrationTest"])

    reports {
        xml.required.set(true)
        html.required.set(true)
    }
}