TeamCity does not parse properly android instrumentation tests coverage

Hi I am trying to setup test coverage on TeamCity for my android project which contains both unit and android tests. 

My problem is that the coverage for unit tests is being handled properly while for android tests always shows zero. The same report generated at my local machine looks fine.

My project uses gradle runner and here is how I configured jacoco to get this report locally:

android.applicationVariants.all { variant ->
def variantName = variant.name.capitalize()

task("jacoco${variantName}TestReport", type: JacocoReport, dependsOn: ["test${variantName}UnitTest", "create${variantName}CoverageReport"]) {

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


def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
sourceDirectories = files(android.sourceSets.main.java.srcDirs)
classDirectories = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug", excludes: fileFilter)
executionData = fileTree(dir: buildDir, includes: [
'/jacoco/testDebugUnitTest.exec',
'outputs/code-coverage/connected/*coverage.ec'
])
}
}

So when I run `./gradlew jacocoDebugTestReport` I can see report which contains combined results of unit and android tests.

To achieve it on TeamCity I use 'service message' mechanism as mentioned here https://confluence.jetbrains.com/display/TCD10/JaCoCo  (I don't use the build-in jacoco coverage option because as far I understand it won't be able to generate report for android tests which doesn't run on jvm)

This service message looks following:

echo "##teamcity[jacocoReport dataPath='app/build/outputs/code-coverage/connected/androidTest.exec app/build/jacoco/testDebugUnitTest.exec' includes='com.elpassion.indoorwayoffice.*' classpath='app/build/tmp/kotlin-classes/debug' sources='app/src/main/java' excludes='**/R.class **/R$*.class **/BuildConfig.* **/Manifest*.* **/*Test*.* android/**/*.*' ]"

(As you can see I had to change the extension of the android tests results file to .exec so the TC can recognise it as a file with results)

Here is my coverage params file:

#
#Tue Sep 12 13:49:30 UTC 2017
teamcity.jacoco.coverage.datafile=app/build/outputs/code-coverage/connected/androidTest.exec app/build/jacoco/testDebugUnitTest.exec
teamcity.coverage.jacoco.excludePatterns=**/R.class **/R.class **/BuildConfig.* **/Manifest*.* **/*Test*.* android/**/*.*
teamcity.coverage.jacoco.includePatterns=com.elpassion.indoorwayoffice.*
teamcity.coverage.jacoco.sources=app/src/main/java
teamcity.coverage.jacoco.classpath=app/build/tmp/kotlin-classes/debug


I use TeamCity version 2017.1 along with jacoco 0.7.5.201505241946

Does anyone have an idea to what the problem might be?

 

--- jacoco.log file:

Jacoco report builder run with arguments: [-dataPaths, 'app/build/outputs/code-coverage/connected/androidTest.exec app/build/jacoco/testDebugUnitTest.exec', -sr, 'app/src/main/java', -cp, 'app/build/tmp/kotlin-classes/debug', -i, 'com.elpassion.indoorwayoffice.*', -e, '**/R.class **/R.class **/BuildConfig.* **/Manifest*.* **/*Test*.* android/**/*.*', -rd, '/opt/buildagent/temp/buildTmp/JACOCO8197527147388694329coverage/report', -t, 'Indoorway Office Android', -l, 'true']
Reading data from /opt/buildagent/work/5021063cef32bf6c/./app/build/jacoco/testDebugUnitTest.exec
Reading data from /opt/buildagent/work/5021063cef32bf6c/./app/build/outputs/code-coverage/connected/androidTest.exec
Exec files loaded in: 64
Filter set up with includes: [com.elpassion.indoorwayoffice.*]; excludes: [**/R.class, **/R.class, **/BuildConfig.*, **/Manifest*.*, **/*Test*.*, android/**/*.*]
100 classfiles analyzed
200 classfiles analyzed
300 classfiles analyzed
400 classfiles analyzed
total 413 classfiles processed, 413 analyzed
Classfiles read in: 334
Info headers read in: 0
Creating SourceCodeFinder from app/src/main/java
File com/elpassion/indoorwayoffice/SharedPreferenceRepository.kt was not found
File com/elpassion/indoorwayoffice/MoshiConverterAdapter.kt was not found
File com/elpassion/indoorwayoffice/login/Action1.kt was not found
File com/elpassion/indoorwayoffice/map/ui/OnHeadingChangedListener.kt was not found
File com/elpassion/indoorwayoffice/map/ui/Action0.kt was not found
File com/elpassion/indoorwayoffice/map/ui/OnPositionChangedListener.kt was not found
File com/elpassion/indoorwayoffice/repository/SharedPreferenceRepository.kt was not found
File com/elpassion/indoorwayoffice/repository/MoshiConverterAdapter.kt was not found
Source files read in: 493
Report written in: 44
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value = '1572']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value = '538']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value = '1527']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value = '577']
##teamcity[buildStatisticValue key='CodeCoverageAbsCTotal' value = '395']
##teamcity[buildStatisticValue key='CodeCoverageAbsCCovered' value = '203']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value = '17907']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value = '6157']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value = '1071']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value = '220']
##teamcity[buildStatisticValue key='JacocoComplexityTotal' value = '2071']
##teamcity[buildStatisticValue key='JacocoComplexityCovered' value = '632']
Jacoco report builder exits normally

---
0

Please sign in to leave a comment.