为espresso android生成测试用例时出错

为espresso android生成测试用例时出错,android,android-gradle-plugin,ui-automation,android-espresso,Android,Android Gradle Plugin,Ui Automation,Android Espresso,我正在跟踪这两个链接,查找浓缩咖啡测试报告,但在运行时出错。/gradlew createDebugCoverageReport。错误将显示在下图中。请帮助我,我无法生成espresso和ui自动化测试用例的报告。现在正在尝试使用jacoco,但无法找到任何解决方案 建造,格雷德尔 apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion '25.0.0'

我正在跟踪这两个链接,查找浓缩咖啡测试报告,但在运行时出错。/gradlew createDebugCoverageReport。错误将显示在下图中。请帮助我,我无法生成espresso和ui自动化测试用例的报告。现在正在尝试使用jacoco,但无法找到任何解决方案

建造,格雷德尔

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.example.project"
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 27
        versionName "1.5"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testCoverageEnabled true
        }
        debug{
            testCoverageEnabled true
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.github.barteksc:android-pdf-viewer:2.0.3'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-annotations:24.2.0'
    androidTestCompile 'com.android.support.test:runner:0.2'
    androidTestCompile 'com.android.support.test:rules:0.2'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'
    androidTestCompile 'com.android.support:support-annotations:24.2.1'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude module: 'support-annotations'
        exclude module: 'recyclerview-v7'



    }
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile "com.android.support.test.espresso:espresso-intents:2.2.2"
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'jacoco'

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

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

有几件事让它运行起来:

确保已按照其他线程检查所有必要条件: 确保已连接的设备已准备好执行测试。模拟器、物理设备或云设备。如果您在IDE中播放测试,它应该显示在“已连接设备”下的“选择部署目标”中。 从项目目录运行Gradlew项目gradle包装器,如下所示:./Gradlew:app:createDebugCoverageReport
有几个问题可以帮助你:1你用什么版本的Android Studio来创建这个项目?2您可以发布build.gradle文件吗?3您的目标是从Android Studio还是从IDE外部运行此功能?此外,我建议按照这个答案中建议的步骤进行:1。Android studio最新版本2.3 2。是的,请检查我的编辑我已经发布了我的构建。gradle 3我想通过Android studio生成我的报告,当我运行代码并排生成报告时。好的,我会检查你提供的链接,然后很快报告你没有从你提供的链接中找到任何帮助。很遗憾听到这个消息,至少我们检查了其他潜在的问题。我相信这是因为您正在目标项目目录之外执行gradle。尝试将目录更改为项目根目录,然后使用特定参数调用gradlew.bat,例如:C:\Users\Aman\YourProjectRoot\gradlew.bat:app:createDebugCoverageReport我在mac上,但当我执行类似的gradle wrapper命令时,覆盖率报告是在./app/reports/androidTests/connectedHey下以HTML文件的形式生成的。它可以正常工作。问题是genymotion没有连接到运行app.Thankx的设备