Gradle & Jacoco: Get jacoco reports for Test-type task other than "test"

2k views Asked by At

When I run gradlew test jacocoTestReport the task jacocoTestReport runs and I get a a test report.
When I run gradlew integTest jacocoTestReport the task jacocoTestReport is skipped.

Here's the relevant excerpts from my build.gradle:

apply plugin: 'jacoco'

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)

    doLast {
        println 'See report at: file://' + projectDir + '/build/reports/jacoco/test/html/index.html'
    }
}


test {
    filter {
        // only run tests ending in *UnitTest
        includeTestsMatching "*UnitTest"
    }
}


task integTest(type: Test) {
    filter {
        includeTestsMatching "*IntegTest"
    }
    jacoco {
        destinationFile = file("$buildDir/jacoco/integTest.exec")
        classDumpFile = file("$buildDir/classes")
    }
}

The gradle documentation doesn't help me here, and extensive googling hasn't produced any results, either.

Any ideas how I can make jacoco do reports for my intergration tests?

EDIT: Unit- & Integration-Tests are in the same directories, they are distinguished by their filenames, just in case that wasn't clear.

1

There are 1 answers

1
Kirby On BEST ANSWER

Turns out, this works:

task integTestReport (type: JacocoReport) {

    executionData project.tasks.integTest

    sourceDirectories = project.files(project.sourceSets.test.allSource.srcDirs)
    classDirectories = project.sourceSets.test.output

    def reportDir = project.reporting.file("jacoco/integTest/html")
    reports {
        html.destination = reportDir
    }
    doLast {
        println "See report at: file://${reportDir.toURI().path}index.html"
    }
}

I hope this is helpful :)

EDIT: This needs to be later in the file than the definition of the integTest task.
I have the whole jacoco-configuration at the end of my build.gradle.