unable to get test coverage report in Espresso

1.1k views Asked by At

Unable to get Espresso Code coverage report, i am new to android studio and tried following set up for generating the report .

Please find the build.gradle setting:

apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'realm-android'
apply plugin: 'jacoco'

 buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            multiDexEnabled true
            testCoverageEnabled true
        }

When i run the recorded test with 'CreateDebugAndroidTestCoverage', i get the following Report:

enter image description here

enter image description here

I am expecting columns with methods, line details etc :

Please find the screen shot for the type of report i am expecting :

enter image description here

1

There are 1 answers

1
Jimit Patel On

You need to add configurations for jacoco report by creating a task in your module's Gradle file (Generally, app/build.gradle). And in that task, you need to add createDebugCoverageReport for depnedsOn property. Let me show you an example of how does it look:

// Task declaration
task jacocoTestReport(type: JacocoReport) {
    // Runs only after the dependencies are executed
    dependsOn = ['testDebugUnitTest', 'createDebugCoverageReport']
    // Export formats
    reports {
        xml.enabled = true
        html.enabled = true
    }

    sourceDirectories.from = files(coverageSourceDirs)
    classDirectories.from = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R*.class'
            ])

    // Inform Gradle where the files generated by test cases - are located
    executionData.from = fileTree(dir: project.buildDir, includes: [
            'jacoco/testDebugUnitTest.exec',
            'outputs/code_coverage/debugAndroidTest/connected/*.ec'
    ])
}

Now, you can run this task with coverage and it will provide you the coverage.