gradle 生成Jacoco报告时排除android Instrumentation测试

xienkqul  于 2023-08-06  发布在  Android
关注(0)|答案(1)|浏览(142)

我在Android应用程序中有多个模块。我需要在CI/CD管道中自动化代码覆盖率报告,它没有物理/虚拟Android设备,也不可能连接设备。
来自-https://github.com/gouline/android-samples/blob/master/jacoco/jacoco.gradle的集成Jacoco
当我尝试通过gradle命令生成覆盖率报告时

>> ./gradlew createDebugCoverageReport

字符串
失败,并显示以下错误日志

* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> com.android.builder.testing.api.DeviceException: No connected devices!


所以我尝试通过命令排除gradle任务(connectdDebugAndroidTest)

>> ./gradlew createDebugCoverageReport -x app:connectedDebugAndroidTest -x module1:connectedDebugAndroidTest


获取错误如下-

> Task :module1:createDebugAndroidTestCoverageReport FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':vpn:createDebugAndroidTestCoverageReport'.
> java.io.IOException: No coverage data to process in directories [/Users/abc/ws/prjName/module1/build/outputs/code_coverage/debugAndroidTest/connected]


我在模块1中有仪器测试
当设备未连接时,如何在生成Jacoco报告时排除仪器测试。

  • 更新 *:

我能够通过以下方式为每个模块单独生成Jacoco报告

./gradlew testDebugUnitTestCoverage


但我在找综合报告。如何将模块中的多个jacoco报告集成到一个报告中?

mrfwxfqh

mrfwxfqh1#

请从jacocoTestReport任务中删除createDebugCoverageReport

task jacocoTestReport(type: JacocoReport,
        dependsOn: ['testDebugUnitTest']) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."

    reports {
        xml.enabled = true
        html.enabled = true
    }

    def fileFilter = ['androidx/**/*.*',
                      '**/view/*.*',
                      '**/data/*.*',
                      '**/data/model/*.*',
                      '**/generated/callback/*.*',
                      '**/lambda$*.class',
                      '**/lambda.class',
                      '**/*lambda.class',
                      '**/*lambda*.class']

    def debugTree = fileTree(dir:
            "${buildDir}/intermediates/javac/debug/classes",
            excludes: fileFilter
    )

    def mainSrc = "/src/main/java"

    sourceDirectories.from = files([mainSrc])

    classDirectories.from = files([debugTree])
    executionData.from = fileTree(dir: "${buildDir}", includes:[
            "/jacoco/testDebugUnitTest.exec"])
}

字符串

相关问题