2

I am using espresso and ui automation for test cases,my test cases are working correct but they are not generating report of pass or fail.For this i search and found jacoco,I tried to use following link https://docs.gradle.org/current/userguide/jacoco_plugin.html According to this link i have added plugin,jacoco version and running app but still report is not generating in debug folder.Tried alot but do not able to find any solution.Please help me in finding solution.

Build.gradle at app level

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'jacoco'
jacoco {
    toolVersion = "0.7.6.201602180812"
    reportsDir = file("$buildDir/customJacocoReportDir")
}
def coverageSourceDirs = [
        'src/main/java',
]
task jacocoTestReport(type: JacocoReport, dependsOn: "connectedDebugAndroidTest") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R*.class'

            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files("$buildDir/jacoco/testDebug.exec")
    // Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
    // We iterate through the compiled .class tree and rename $$ to $.
    doFirst {
        new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}
Shivam Kapoor
  • 117
  • 1
  • 13
  • is this question different than our working thread in? http://stackoverflow.com/questions/43094105/getting-error-while-generating-test-cases-for-espresso-android?noredirect=1#comment73342561_43094105 – Paul Bruce Mar 31 '17 at 12:04
  • I already resolved this.As i am adding jacoco in build.gradle at app level but when i add in build.gradle at project level.It works.Can u plz help in resolving this error,spend many hours on this. http://stackoverflow.com/questions/43136553/complete-logintest-does-not-run-in-android-using-espresso – Shivam Kapoor Mar 31 '17 at 12:15

1 Answers1

0

You can generate Test Coverage Reports setting testCoverageEnabled parameter to true in your build.gradle file:

android { buildTypes { debug { testCoverageEnabled = true } } }

Then use:

./gradlew connectedCheck

or

./gradlew createDebugCoverageReport

It will produce a test coverage report in the directory of the module:

/build/outputs/reports/coverage/debug/

Just open the index.html