0

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?

Astha Garg
  • 1,022
  • 7
  • 21

2 Answers2

0

You might need to do the following

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
}

Note that there are some issues with Java 11 that might fail your tests so you might want to also exclude jdk.internal as follows

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
    excludes = ['jdk.internal.*']
}

Or a little bit verbose option but works:

subprojects {
    pluginManager.withPlugin("com.android.library"){
        android.testOptions.unitTests.all {
            jacoco {
                includeNoLocationClasses = true
                excludes = ['jdk.internal.*']
            }
        }
    }
    pluginManager.withPlugin("com.android.application"){
        android.testOptions.unitTests.all {
            jacoco {
                includeNoLocationClasses = true
                excludes = ['jdk.internal.*']
            }
        }
    }
    apply plugin: 'jacoco'
}

I suggest you also upgrade your jacoco and sonar plugin versions if possible

  • I have updated my question a bit, can you please check that and help here – Astha Garg Dec 02 '21 at 06:44
  • Is this still happening? If yes, can you share a project with the issue? – mina ashraf Feb 15 '22 at 12:19
  • Yes, but I can't share the project. Can you please check the update part in my question that's the current state. When I move pkgB files to pgA then it's showing coverage for those files – Astha Garg Feb 15 '22 at 13:12
0

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'
Astha Garg
  • 1,022
  • 7
  • 21