0

I am following these two links 1 and 2 for espresso test report but getting error while running ./gradlew createDebugCoverageReport. The error will be shown in image given below. Please help me, I am not able to generated report for espresso and ui automation test cases. Now trying to use jacoco but not able to find any solution. image

Build.Gradle

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"
    ])
}
Community
  • 1
  • 1
Shivam Kapoor
  • 117
  • 1
  • 13
  • A few questions to help you out: 1) what version of Android Studio are you using to create the project? 2) can you post your build.gradle file? 3) is your goal to run this from Android Studio or from outside the IDE? Also, I suggest going through the suggested steps in this answer: http://stackoverflow.com/a/25525390/3195307 – Paul Bruce Mar 29 '17 at 13:36
  • 1). Android studio latest version 2.3 2).Yes plz check my edit i have posted my build.gradle 3)I want to generate my report through android studio when i run the code side by side report should be generated. And okey,i will check the link u provided,and soon report you – Shivam Kapoor Mar 30 '17 at 04:08
  • Did not find any help from link you provided – Shivam Kapoor Mar 30 '17 at 04:22
  • 1
    Sorry to hear that, at least we checked those other potential issues. I believe this is because you're executing gradle outside the target project directory. Try changing directories to be in the root of the project, then call the gradlew.bat with specific parameters such as: C:\Users\Aman\YourProjectRoot\gradlew.bat :app:createDebugCoverageReport I'm on a mac, but when I execute the analogous gradle wrapper command, coverage report is generated as an HTML file under ./app/reports/androidTests/connected – Paul Bruce Mar 30 '17 at 13:47
  • I tried,but getting error FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:connectedDebugAndroidTest'. > com.android.builder.testing.api.DeviceException: No connected devices! * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED – Shivam Kapoor Mar 31 '17 at 04:01
  • 1
    Hey,it works.The issue is of genymotion as no device connected to run app.Thankx paul – Shivam Kapoor Mar 31 '17 at 04:12
  • really glad to hear! can you accept the answer I posted? thx. – Paul Bruce Mar 31 '17 at 12:02

1 Answers1

1

A few things that got this running:

  1. Make sure that all the requisites are checked, per this other thread: https://stackoverflow.com/a/25525390/3195307
  2. Make sure there is a connected device ready to execute your tests. Emulator, physical device, or cloud device. It should show in 'Select Deployment Target' under 'connected devices' if you play your tests in IDE.
  3. Run Gradlew (project gradle wrapper) from the project directory like so: ./gradlew :app:createDebugCoverageReport
Community
  • 1
  • 1
Paul Bruce
  • 554
  • 2
  • 7