3

I'm working in a multi-module Android project with an application module and a library module. If I simply add

apply plugin: 'jacoco'
jacoco {
     toolVersion '0.8.7'
}

to the build.gradle for each module, then when I run the off-device unit tests from the command line in each module's directory, I see an .exec file created at build/jacoco/testDebugUnitTest.exec with a size of ~27k or so. Generating a report from this does what I'd expect.

If I add

buildTypes {
    debug {
        testCoverageEnabled true
    }
}

to the build.gradle for each module (so that I can later gather coverage numbers for on-device tests as well) then when I run the off-device unit tests the .exec file is instead created in build/outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec.

More importantly, while that file is still ~27k when I'm running the tests in the application module, it is almost empty (only 45 bytes) when I'm running the tests in a library module in the same project.

Is there a reason testCoverageEnabled interferes with off-device code coverage for library modules but not for the primary application module?

Aidan64
  • 573
  • 1
  • 5
  • 12
  • Are you using gradle 7.0 ? If so, check out https://issuetracker.google.com/issues/195860510. I have a library project too and was facing issues with empty exec file with gradle 7.0. It was working fine in gradle 4.0.2.. The work around with `testCoverageEnabled false` worked with gradle 7.0 and my coverage for my library is fine now. – onusopus May 19 '22 at 00:40

0 Answers0