Gradle - Jacoco只执行单元测试而不抛出设备未找到异常

时间:2018-05-15 21:04:27

标签: android-gradle jacoco

我正在尝试仅执行单元测试和genrate jacoco测试报告,但我总是看到一条失败消息说

Execution failed for task ':App:connectedDebugAndroidTest'.
> com.android.builder.testing.api.DeviceException: No connected devices!

Gradle代码:

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.8.1"
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testTpsDebugUnitTest', 'create<build-vairant>DebugCoverageReport']) { 
    group = "reporting"
    description = "Generate unified Jacoco code coverage report"

    reports {
        xml.enabled false
        csv.enabled false
        html.destination  file("${buildDir}/reports/jacocoHtml")
    }

    def fileFilter = [
            '**/*Test*',
            '**/*_MembersInjector.class',
            '**/*_Factory.class']
    def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/<build-variant>/debug", excludes: fileFilter)
    def mainSrc = "${project.projectDir}/src/main/java"

    sourceDirectories = files([mainSrc])
    classDirectories = files([debugTree])
    executionData = fileTree(dir: "$buildDir", includes: [
            "jacoco/test<build-variant>DebugUnitTest.exec"
    ])

我用命令执行:

 ./gradlew -Pcoverage clean jacocoTestReport

请帮助解决此问题,因此它只执行单元测试并且不要求设备!

0 个答案:

没有答案