Search code examples
androidkotlinsonarqubeintegration-testingjacoco

Sonar Jacoco not considering Kotlin androidTest (integration test case) in coverage


I have local and integrated test cases written for my android project. Using Kotlin(1.4.21) Robolectric(4.5.1), sonar(2.7.1), Jacoco(maven plugin 0.8.2)

The problem is that the Sonar and Jacoco is not considering androidTest(integration test case) written in Kotlin for code coverage However sonar is showing correct coverage for other test cases like-

java unit test cases -> working

koltin unit test case -> working

java integrated test cases -> working

kotlin integrated test cases -> NOT WORKING

Although I have checked the paths I have set for sonar and it's all correct.

properties['sonar.java.binaries'] = files("${buildDir}/intermediates/javac/universalDebug/classes")
properties["sonar.java.binaries"] += files("${buildDir}/tmp/kotlin-classes/universalDebug/")

properties['sonar.java.test.binaries'] = files("${buildDir}/intermediates/javac/universalDebugAndroidTest/classes")
properties['sonar.java.test.binaries'] += files("${buildDir}/tmp/kotlin-classes/universalDebugAndroidTest/")

I have gone through other stackoverflow questions but didn't find same problem. So, I'm unable to find out the issue why sonar is not showing coverage for my integrated test cases written in Kotlin.

Thanks in Advance

UPDATE

within adroidTest folder > I have further 2 packages.

MyApplicationTest> src> com > pkgA
                            > pkgB

It's considering the Tests files present in pkgA but not the other. I have recently created this pkgB What could be the possible reason for this? Do I have update some path somewhere?


Solution

  • This was not sonar's fault, it was missing from the code itself.

    In build.gradle we were setting the package of the first folder only that's why sonar was not considering the Test files under the another package.

    Changed from

    testInstrumentationRunnerArguments 'package': 'com.pkgA'
    

    to

     testInstrumentationRunnerArguments 'package': 'com'