简体   繁体   English

JaCoCo 与 Gradle Kotlin 多模块 Android 项目 - isTestCoverageEnabled 实际上是做什么的?

[英]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).我正在配置一个 Android 多模块 Gradle 项目,该项目将 Kotlin 用于应用程序和 Z7B5CC4FB56E11DC75Z0F0FAZ 构建文件(gradlele6E11DC75Z0F0FAZ)构建文件)

I'm using Gradle 7.3.3.我正在使用 Gradle 7.3.3。

First I add the Jacoco plugin to the module-level build.gradle.kts:首先,我将 Jacoco 插件添加到模块级 build.gradle.kts:

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

Then I click the icon in Android Studio to "sync project with gradle files."然后我单击 Android Studio 中的图标以“将项目与 gradle 文件同步”。

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 .当我随后运行./gradlew testDebugUnitTest时,会在<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 .但是,如果我不添加行isTestCoverageEnabled = true ,或者如果我设置isTestCoverageEnabled = false ,则会在<MODULE>/build/jacoco/testDebugUnitTest.exec的模块中生成覆盖结果文件。

When I generate each.exec file's HTML report, the "Total" rows at the bottom have matching counts.当我生成 each.exec 文件的 HTML 报告时,底部的“Total”行具有匹配的计数。

Are these two files equivalent, but just located in different directories depending on the value of isTestCoverageEnabled ?这两个文件是否等效,但根据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.如果是这样,似乎只要在插件中包含 jacoco,无论是否添加isTestCoverageEnabled = true行,都会生成覆盖结果。 Does isTestCoverageEnabled do anything else besides change the output directory?除了更改isTestCoverageEnabled目录之外,isTestCoverageEnabled 是否还有其他操作? 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).我在多个项目中为这个问题苦苦挣扎了 3 年,但我有一个解决方案(或者更确切地说是有人解决了我的问题)。

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. Android-Root-Coverage-Plugin可用于在 Java 和/或 Kotlin 多模块项目中组合 jUnit 和仪器测试,无需任何其他配置。 It resolved my following issues:它解决了我的以下问题:

  • Getting coverage in multi module project在多模块项目中获得覆盖
  • Incorrect coverage in Kotlin Kotlin 中的错误覆盖
  • Combining both jUnit & Instrumented test coverage结合 jUnit 和仪表测试覆盖率

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.已确认我的问题的原因是由于 android gradle 插件中的错误,截至 2022 年 8 月,该问题尚未解决。

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.具体到您的问题, isTestCoverageEnabled用于配置 android gradle 插件中的嵌入式 JaCoCo,如上所述,已知该插件存在错误。 Using the JaCoCo plugin can be configured in the gradle file but does not utilise the embedded JaCoCo in AGP使用 JaCoCo 插件可以在 gradle 文件中配置,但不使用 AGP 中的嵌入式 JaCoCo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Intellij IDEA 13.1.13中具有Android + Gradle的多模块项目 - Multi-module project in Intellij IDEA 13.1.13 with Android+Gradle 使用 Jacoco 测量多模块和动态功能模块 Android 项目中的测试覆盖率 - Measuring tests coverage in multi-module and dynamic feature module Android project using Jacoco 如何在多模块 android 项目(kotlin + java)上配置 SonarQube(使用 jacoco)? - How to configure SonarQube (with jacoco) on multi module android project (kotlin + java)? 如何为多模块项目创建汇总的 Jacoco 报告? - How to create an aggregated Jacoco report for a multi-module project? 具有多模块android库的Gradle配置 - Gradle configuration with multi-module android library Jacoco gradle“排除”在使用 Kotlin 的 Android 项目中不起作用 - Jacoco gradle 'exclude' not working in Android project with Kotlin 将多模块 gradle 脚本转换为 kotlin dsl 时遇到问题 - Trouble converting multi-module gradle script to kotlin dsl Android多模块项目因TypeNotPresentException失败 - Android multi-module project fails with TypeNotPresentException 更新到android gradle插件2.3后,多模块MultiDex项目不会运行测试 - Multi-module MultiDex project won't run tests after update to android gradle plugin 2.3 如何在Gradle多模块项目中使用ObjectBox? - How to use ObjectBox in Gradle multi-module project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM