包括Android工具测试时如何运行jacocoTestReport?

时间:2018-12-07 15:44:29

标签: android android-gradle reporting jacoco

我的Android应用同时包含单元测试和仪器测试,我想使用JaCoCo插件生成一份覆盖率报告(然后最终移植到coveralls.io)。但是我似乎无法在本地计算机上运行gradlew jacocoTestReport,因为我没有连接到Android Studio的仿真器或设备。错误和完整日志位于https://pastebin.com/c7vcwseF

这是我的应用build.gradle中包含任务定义的部分:

# ...
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: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter)
    def mainSrc = "$project.projectDir/src/main/java"

    sourceDirectories = files([mainSrc])
    classDirectories = files([debugTree])
    executionData = fileTree(dir: project.buildDir, includes: [
            'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
    ])
}

coveralls {
    jacocoReportPath 'build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml'
}
# ...

我正在Android项目中使用org.jacoco:org.jacoco.core:0.8.2插件。

那么,一个人如何运行gradlew jacocoTestReport并在本地生成报告?

0 个答案:

没有答案