1

I'm trying to exclude packages when running the createDebugCoverageReport task, but with no success. I've tried solutions like these:

And I've tried to edit the task itself where there is a option to exclude packages from coverage data: enter image description here

dotdolfin
  • 105
  • 7

1 Answers1

1

For some reason excludes didn't work, so I fixed with includes. Here is the code, it will combine unit tests and instrumented tests in a single coverage report.

task codeCoverageReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
    reports {
        xml.enabled = true
        html.enabled = true
        csv.enabled = true
    }

    def includeFiles = [
            '**/database/**/*.*',
            '**/repository/**/*.*',
            '**/network/worker/*.*',
            '**/util/extensions/*.*'
    ]

    def mainSrc = "${project.projectDir}/src/main/java"

    classDirectories.from =
            fileTree(
                    dir: "$buildDir/intermediates/app_classes/debug",
                    includes: includeFiles
            ) + fileTree(
                    dir: "$buildDir/tmp/kotlin-classes/debug",
                    includes: includeFiles
            )
    sourceDirectories.from = files([mainSrc])
    executionData.from =
            fileTree(dir: "$buildDir", includes: [
                    "jacoco/testDebugUnitTest.exec",
                    "outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
            ])
}
dotdolfin
  • 105
  • 7