简体   繁体   中英

JaCoCo with Gradle Kotlin multi-module Android project - what does isTestCoverageEnabled actually do?

I'm configuring an Android multi-module Gradle project that uses Kotlin for both the app AND the Gradle build files (gradle.build.kts).

I'm using Gradle 7.3.3.

First I add the Jacoco plugin to the module-level build.gradle.kts:

...
plugins {
    ...
    jacoco
}
...

Then I click the icon in Android Studio to "sync project with gradle files."

Next, I find the debug build type and add this:

isTestCoverageEnabled = true

When I subsequently run ./gradlew testDebugUnitTest , a file is generated in the module at <MODULE>/build/outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec .

If, however, I don't add the line isTestCoverageEnabled = true , or if I set isTestCoverageEnabled = false , a coverage results file is generated in the module at <MODULE>/build/jacoco/testDebugUnitTest.exec .

When I generate each.exec file's HTML report, the "Total" rows at the bottom have matching counts.

Are these two files equivalent, but just located in different directories depending on the value of isTestCoverageEnabled ?

If so, it seems that, as long as jacoco is included in the plugins, coverage results are generated regardless of whether the isTestCoverageEnabled = true line is added. Does isTestCoverageEnabled do anything else besides change the output directory? What am I missing?

I have struggled with this issue for 3 years across multiple projects, but I have a solution (or rather someone who resolved my issues).

The Android-Root-Coverage-Plugin can be used to combine both jUnit and instrumented tests in a Java and/or Kotlin multi module project without any great need to configure anything else. It resolved my following issues:

  • Getting coverage in multi module project
  • Incorrect coverage in Kotlin
  • Combining both jUnit & Instrumented test coverage

It has been confirmed that the cause of my issues were due to a bug in the android gradle plugin and as of Aug, 2022 it has yet to be resolved.

Specific to your question, isTestCoverageEnabled is used to configure the embedded JaCoCo in the android gradle plugin, which as stated above, is known to be buggy. Using the JaCoCo plugin can be configured in the gradle file but does not utilise the embedded JaCoCo in AGP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM