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:
Thanks!!!
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With