0

ここで説明されているように、CodeCov/Jacoco を実装しようとしています。

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

このガイドは、アプリ レベルの build.gradle.

ただし、build.gradle で「com.android.library」を使用してライブラリとして指定されている video_library という 2 番目のライブラリ モジュールがあります。

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)))

dirJava ではパスが異なるため、パスを試してみてください

于 2021-09-23T10:12:24.013 に答える