Gradle & Jacoco:获取 "test" 以外的测试类型任务的 jacoco 报告

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

当我 运行 gradlew test jacocoTestReport 任务 jacocoTestReport 运行s 并且我得到一份测试报告时。
当我 运行 gradlew integTest jacocoTestReport 任务 jacocoTestReport 被跳过。

这是我的 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")
    }
}

gradle 文档在这里对我没有帮助,广泛的谷歌搜索也没有产生任何结果。

有什么想法可以让 jacoco 为我的集成测试生成报告吗?

编辑:单元测试和集成测试位于同一目录中,它们通过文件名区分,以防万一不清楚。

事实证明,这有效:

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"
    }
}

希望对您有所帮助:)

编辑:这需要在文件中晚于 integTest 任务的定义。
我的 build.gradle.

末尾有整个 jacoco 配置