gradletestingjacocogradle-taskjacoco-plugin

With the Gradle JaCoCo plugin, how to include coverage data of an additional test task?


I am using Gradle in version 8.13.

I am using the Gradle JaCoCo Plugin.

Besides the default Gradle test task, I have added an additional test task to some of the Gradle subprojects:

var integrationTestTask = tasks.register<Test>("integrationTest") {
   …
}

How can I tell the Gradle JaCoCo plugin to generate the coverage data for the integrationTestTask and include it to the coverage data of the default Gradle test task?


Solution

  • This only works when the test suites are created with the JVM Test Suite plugin:

    testing {
        suites { 
            val test by getting(JvmTestSuite::class) { 
                useJUnitJupiter() 
            }
    
            register<JvmTestSuite>("integrationTest") { 
                dependencies {
                    implementation(project()) 
                }
    
                targets { 
                    all {
                        testTask.configure {
                            shouldRunAfter(test)
                        }
                    }
                }
            }
        }
    }