Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco data file not readable for Android on TeamCity

I´m learning TeamCity Integration Server today and I´m trying yo enable Jococo Reports with my Android Gradle based Application.

This document shows me how to enable Jococo coverage, with the following warning:

Make sure your tests run in the fork=true mode. Otherwise the coverage data may not be properly collected.

I don´t know what should I do to "run my tests in fork=true mode". TeamCity isn´t generating coverage reports and is warning me with the following log:

Jacoco data file path specified as C:\TeamCity\buildAgent\temp\buildTmp\JACOCO5884661263301729570coverage\jacoco.exec but is not readable. Coverage will not be collected.

I think that this warning is related to not running the test in fork=true mode.

So, my question is:

  1. What fork=true mode means and
  2. How to enable it at gradle?

Thanks!!!

like image 805
regisxp Avatar asked Feb 06 '15 23:02

regisxp


1 Answers

After some research, I was able to instruct Teamcity to process coverage reports generated by jacoco using "services message" technique, explained on this:

Since TeamCity 9.0, TeamCity is able to parse JaCoCo coverage data and generate a report using a service message of the following format:

##teamcity[jacocoReport dataPath='<path to jacoco.exec file>']

So, I modified my build.gradle file adding the folowing lines to jacocoTestReport section:

if (project.hasProperty("teamcity")) {
    println '##teamcity[jacocoReport dataPath=\'app/build/jacoco/testDebug.exec\' includes=\'com.mynamespace.myproject.*\' excludes=\'**/R.class **/R$*.class **/*$ViewInjector*.* **/BuildConfig.* **/Manifest*.*\']'
}

After that, the complere jacocoTestReport was:

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
    group = "Reporting"

    description = "Generate Jacoco coverage reports"

    classDirectories = fileTree(
            dir: '../app/build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/*$ViewInjector*.*',
                       '**/BuildConfig.*',
                       '**/Manifest*.*']
    )

    additionalSourceDirs = files(coverageSourceDirs)
    sourceDirectories = files(coverageSourceDirs)

    executionData = files('../app/build/jacoco/testDebug.exec')
    if (project.hasProperty("teamcity")) {
        println '##teamcity[jacocoReport dataPath=\'app/build/jacoco/testDebug.exec\' includes=\'com.mynamespace.myproject.*\' excludes=\'**/R.class **/R$*.class **/*$ViewInjector*.* **/BuildConfig.* **/Manifest*.*\']'
    }

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

}

And the Teamcity started to report CodeCoverage as belows:

enter image description here

like image 190
regisxp Avatar answered Oct 13 '22 19:10

regisxp