Friday, 16 July 2021

SonarQube Code Coverage Could not account for Kotlin files on an Android Project

Below is my sonarqube properties snippet:

sonarqube {
   properties{
      property "sonar.junit.reportPaths", "build/test-results/testDebugUnitTest/*.xml"
      property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacocoTestReport.xml"
}
}

Jacoco configuration and properties are working fine, how did I confirm this? I created a java class and wrote a unit test for it, sonarqube recognises this and recorded it as part of the Code Coverage, while it basically ignore all the Kotlin file test. I went ahead to change a kotlin file to java and also write a UnitTest for it and yes, it got recorgnised and add as part of the Code Coverage, again, the kotlin file tests were ignored.

Below is my Jacoco.gradle by the way:

apply plugin: 'jacoco'

ext {
    coverageExclusions = [
            '**/*Activity*.*',
            '**/*Fragment*.*',
            '**/R.class',
            '**/R$*.class',
            '**/BuildConfig.*',
    ]
}

jacoco {
    toolVersion = '0.8.6'
    reportsDir = file("$buildDir/reports")
}

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


tasks.withType(Test) {
    finalizedBy jacocoTestReport // report is always generated after tests run
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports for Debug build"

    reports {
        xml.enabled(true)
        html.enabled(true)
        xml.destination(file("build/reports/jacocoTestReport.xml"))
    }

    def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug/classes", excludes: coverageExclusions)
    def mainSrc = "/src/main/java"

    additionalSourceDirs.from = files(mainSrc)
    sourceDirectories.from = files([mainSrc])
    classDirectories.from = files([debugTree])

    executionData.from = fileTree(dir: project.buildDir, includes: [
            'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
    ])


from SonarQube Code Coverage Could not account for Kotlin files on an Android Project

No comments:

Post a Comment