Get coverage info from a coverage.ec file

3.5k Views Asked by At

I was using a tool for mobile testing that produces coverage reports on a file called coverage.ec (using EMMA). The file is not readable but I would like to know how to access the info it contains. I just need to read the coverage percentage in general.

1

There are 1 best solutions below

0
Stephen Ruda On

I was on a very similar situation. I had a coverage.ec file and I had no idea how to convert it into a readable report. This article was very helpful for me.

There is a lot more information there than you may need, but for me the important part was adding this to build.gradle:

apply plugin: 'jacoco'

def coverageSourceDirs = [
'src/main/java',
'src/debug/java']

task jacocoTestReport(type : JacocoReport, dependsOn : 'testDebugUnitTest') {
group       = 'Reporting'
description = 'Generate JaCoCo coverage reports'

reports {
    xml.enabled  = true
    html.enabled = true
}

classDirectories = fileTree(
    dir      : 'build/intermediates/classes/debug',
    excludes : [
        '**/R.class',
        '**/R$*.class',
        '**/*$ViewInjector*.*',
        '**/*$ViewBinder*.*',
        '**/BuildConfig.*',
        '**/Manifest*.*',
        '**/*RealmProxy.*',
        '**/*ColumnInfo.*',
        '**/*RealmModule*.*',
        '**/AutoValue_*.*',
        '**/Dagger*.*',
        '**/*Module_Provide*Factory.*',
        '**/*_Factory.*',
        '**/*_MembersInjector.*',
        '**/*_LifecycleAdapter.*'
    ]
)

sourceDirectories = files(coverageSourceDirs)
executionData     = fileTree(
    dir     : "$buildDir",
    include : [ 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec' ]
)

doFirst {
    files('build/intermediates/classes/debug').getFiles().each { file ->
        if (file.name.contains('$$')) {
            file.renameTo(file.path.replace('$$', '$'))
        }
    }
}}

From here, I placed my coverage.ec file in my app/build/outputs/code-coverage/connected/coverage.ec.

After that, I ran the jacocoTestReport gradle task and it generates a merged report for my unit tests and the reports from the coverage.ec file located in app/build/reports/jacoco/jacocoTestReport/html/index.html

Hope this helps!