Gradle无法找到testDebug'任务

时间:2015-07-21 23:34:33

标签: android gradle jacoco android-espresso

我试图让Jacoco与Espresso合作,但是当我尝试按照

这样的例子时

http://raptordigital.blogspot.com/2014/08/code-coverage-reports-using-robolectric.html

jacocoTestReport任务取决于' testDebug' Gradle告诉我的任务无法在项目中找到。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

testDebug是您的单元测试的任务(假设您使用的是android gradle插件v1.2 +或其他一些单元测试插件)。您正在寻找的是connectedAndroidTest任务或其风格。

Here是完整的jacocoTestReport任务,适用于espresso测试。

apply plugin: 'jacoco'
jacoco {
    version "0.7.1.201405082137"
}

task jacocoTestReportAndroidTest(type: JacocoReport, dependsOn: "connectedAndroidTest") {
    def coverageSourceDirs = [
            'src/main/java'
    ]
    group = "Reporting"
    description = "Generates Jacoco coverage reports"
    reports {
        csv.enabled false
        xml{
            enabled = true
            destination "${buildDir}/reports/jacoco/jacoco.xml"
        }
        html{
            enabled true
            destination "${buildDir}/jacocoHtml"
        }
    }
    classDirectories = fileTree(
            dir: 'build/intermediates/classes',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/BuildConfig.*',
                       '**/Manifest*.*',
                       '**/*Activity*.*',
                       '**/*Fragment*.*'
            ]
    )
    sourceDirectories = files(coverageSourceDirs)
    additionalSourceDirs = files(coverageSourceDirs)

    if (project.hasProperty('coverageFiles')) {
        // convert the comma separated string to an array to create an aggregate report from
        // multiple coverage.ec files
        def coverageFilesArray = coverageFiles.split(',')
        executionData = files(coverageFilesArray)
    }
    else {
        executionData = files('build/outputs/code-coverage/connected/coverage.ec')
    }
}