【问题标题】:Generate test coverage report in android studio 2.3 using espresso and ui automator使用 espresso 和 ui automator 在 android studio 2.3 中生成测试覆盖率报告
【发布时间】:2017-03-30 09:39:07
【问题描述】:

我正在使用 espresso 和 ui 自动化测试用例,我的测试用例工作正常,但它们没有生成通过或失败的报告。为此,我搜索并找到了 jacoco,我尝试使用以下链接 https://docs.gradle.org/current/userguide/jacoco_plugin.html 根据这个链接我已经添加了插件、jacoco 版本和正在运行的应用程序,但仍然没有在调试文件夹中生成报告。尝试了很多但找不到任何解决方案。请帮助我找到解决方案。

应用级别的Build.gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'jacoco'
jacoco {
    toolVersion = "0.7.6.201602180812"
    reportsDir = file("$buildDir/customJacocoReportDir")
}
def coverageSourceDirs = [
        'src/main/java',
]
task jacocoTestReport(type: JacocoReport, dependsOn: "connectedDebugAndroidTest") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R*.class'

            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files("$buildDir/jacoco/testDebug.exec")
    // Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
    // We iterate through the compiled .class tree and rename $$ to $.
    doFirst {
        new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}

【问题讨论】:

标签: android ui-automation jacoco android-espresso


【解决方案1】:

您可以在 build.gradle 文件中将 testCoverageEnabled 参数设置为 true 来生成测试覆盖率报告:

机器人{ 构建类型 { 调试{ testCoverageEnabled = 真 } } }

然后使用:

./gradlew connectedCheck

./gradlew createDebugCoverageReport

它会在模块目录下生成测试覆盖率报告:

/build/outputs/reports/coverage/debug/

只需打开index.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2016-11-18
    • 2019-02-11
    相关资源
    最近更新 更多