Sonarqube don't found the Kotlin UnitTest classes

Hi there,

We developed Android App written in Kotlin, Kotlin unit-test classes are not export to Sonarqube dashboard, but for Java unit-test classes work well and export to Sonarqube unit-test

The sonarqube plugin has not found the kotlin classes although they exists - full error message on the bottom.

Please advise what we should do? if there is any document or article kindly share it with us.

Versions:
SonarQube > Developer EditionVersion 9.0.1 (build 46107)
SonarScanner for Gradle plugin > 3.3

Sonarqube properties:

sonarqube {
    properties {
        property "sonar.projectName", "Android-APPPP"
        property "sonar.projectKey", "com.exa.aaa"
        property "sonar.sources", ["src/main/java"]
        property "sonar.tests", ["src/test/java","src/test/kotlin"]
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.test.inclusions", "**/*Test*/**"
        property "sonar.exclusions", '**/*Test*/**,' +
                'build/**' +
                '*.json,' +
                '**/*test*/**,' +
                '**/.gradle/**,' +
                '**/*Generated.java,'+
                '**/R.class'
        property "sonar.junit.reportPaths", "${project.projectDir}/build/test-results/testDebugUnitTest"

    }
}

Steps:

  1. ./gradlew test
  2. ./gradlew sonarqube

Next error messages shows

> Task :app:sonarqube
Resource not found: android.example.com.changelanguge.AppTest under the directory /Users/ahmedqamar/StudioProjects/ChangeLanguge/app while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly
Resource not found: android.example.com.changelanguge.MainActivityTest under the directory /Users/ahmedqamar/StudioProjects/ChangeLanguge/app while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly
Resource not found: android.example.com.changelanguge.ExampleUnitTest under the directory /Users/ahmedqamar/StudioProjects/ChangeLanguge/app while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly

Sample project I try to integrate Sonarqube

Hello,

I took your reproducer and changed this in the config:

  • remove the SonarQube configuration from the app/build.gradle file
  • put the SonarQube config in the top level build.gradle file like this
plugins {
  id "org.sonarqube" version "3.3"
}

sonarqube {
  properties {
    property "sonar.projectKey", "ahmed_unit_test_sonar"
    property "sonar.junit.reportPaths", "${project.projectDir}/app/build/test-results/testDebugUnitTest"   
  }
}

Then I executed this command:

./gradlew test sonarqube   -Dsonar.projectKey=ahmed_unit_test_sonar   -Dsonar.host.url=https://changeme   -Dsonar.login=changeme -i*

In the logs, I have the same weird message like you:

Sensor KotlinSurefireSensor [kotlin]
parsing [/home/alex/Repos/Android_Validation/Kotlin/ahmed_unit_test_sonar/app/build/test-results/testDebugUnitTest]
Searching for android/example/com/changelanguge/AppTest
Resource not found: android.example.com.changelanguge.AppTest under the directory /home/alex/Repos/Android_Validation/Kotlin/ahmed_unit_test_sonar/app while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly
Searching for android/example/com/changelanguge/MainActivityTest
Searching for android/example/com/changelanguge/ExampleUnitTest

I don’t deny that there is a problem somewhere in KotlinSurefireSensor, still at the end, on SonarQube I see that there are 3 Tests as expected:

Alex

1 Like

Hi Alex,
I found the issue that prevents unit tests from shows on SonarQube

The issue was the name of the unit test class was different from an original class name, because when creating the unit-test class it’s added by default suffix *Test word.

  • FeatureLogic.kt >>> the original class
  • FeatureLogicTest.kt >>> the test class it’s finish with suffix *Test

Is there any way to make KotlinSurefireSensor see FeatureLogicTest as a test class for FeatureLogic ?.

I appreciate you’re help

Thank you so much @Alexandre_Gigleux :tulip:
I make changes from your replay and it works well now.

You need to add sonar.projectKey in Sonarqube properties

as next

sonarqube {
  properties {
    property "sonar.projectKey", "ahmed_unit_test_sonar"
    property "sonar.junit.reportPaths", "${project.projectDir}/app/build/test-results/testDebugUnitTest" 
    property "sonar.projectKey", "com.ahmed.app"
  }
}

Also, I found the next property reason of the issue I faced in my case

property "sonar.test.inclusions", "**/*Test*/**"