0

我正在尝试按照此处所述实现 CodeCov/Jacoco:

https://about.codecov.io/blog/code-coverage-for-android-development-using-kotlin-jacoco-github-actions-and-codecov/

本指南非常适用于主应用程序模块,在应用程序级 build.gradle 中使用 'com.android.application 指定。

但是,我有第二个名为 video_library 的库模块,它被指定为在其 build.gradle 上带有“com.android.library”的库。

每当我尝试为 video_library 模块运行 Jacoco 任务时,这些任务都会运行,但它无法运行我编写的任何单元测试,就好像它找不到任何测试一样(尽管这个模块有超过 50 个)

在此处输入图像描述

项目结构如下:

├── app
│   ├── build
│   └── src
├── build
│   └── kotlin
├── gradle
│   └── wrapper
└── library_video
    ├── build
    ├── sampledata
    └── src

我以与 app 模块相同的方式实现了 jacocoTestReport:

plugins {
        id 'com.android.library'
        id 'kotlin-android'
        id 'kotlin-kapt'
        id 'org.jetbrains.dokka'
        id 'maven-publish'
        id 'jacoco'
    }
    
    task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
    
        reports {
            xml.enabled = true
            html.enabled = true
        }
    
        def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
        def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
        def mainSrc = "${project.projectDir}/src/main/java"
    
        sourceDirectories.setFrom(files([mainSrc]))
        classDirectories.setFrom(files([debugTree]))
        executionData.setFrom(fileTree(dir: "$buildDir", includes: [
                "jacoco/testDebugUnitTest.exec",
                "outputs/code-coverage/connected/*coverage.ec"
        ]))
    }

是否需要对 library_video 模块实现进行调整才能找到测试?

4

1 回答 1

0

您需要在模块中classDirectories library_video手动包含类。:app这至少是帮助我实现多模块代码覆盖的原因。

:app模块中(我使用的是 Gradle KTS,因此在 Kotlin 中):

val library_video_dir = fileTree(mapOf("dir" to "${buildDir}/../../library_video/build/classes/kotlin/main", "excludes" to fileFilter))

classDirectories.setFrom(files(listOf(debugTree, library_video_dir)))

尝试使用dir路径,因为它与 Java 不同

于 2021-09-23T10:12:24.013 回答