Unable to import / view junit test report code coverage in Sonarqube Version 6.3.1 (build 21392)

coverage

(Classtest) #1

Unable to import / view junit test report code coverage in Sonarqube Version 6.3.1 (build 21392).

Used this lines :
sonar.projectKey=devtest
sonar.projectName=devtest
sonar.sourceEncoding=UTF-8
sonar.sources=modules/war/src,modules/jar/src
sonar.java.source=modules/war/src,modules/jar/src
sonar.java.binaries=modules/jar/classes,modules/war/classes
sonar.junit.reportPaths=dist/test-reports
sonar.junit.reportsPath=dist/test-reports

Able to generate report through Jenkins using above sonar properties but unable import / view junit test report code coverage in Sonarqube.

Here is the result which is getting after the build process completes in Jenkins:
[Coverage] [0.0%]

Please guide me on how to get junit test report code coverage result in sonarqube.


(Nicolas Bontoux) #2

Hi,

Well first of all it’s surprising to use both of these:

sonar.junit.reportPaths=dist/test-reports
sonar.junit.reportsPath=dist/test-reports

You should refer to Java Unit Tests and Coverage Results Import documentation for the recommendations on that topic.

That same documentation will show how coverage numbers can be imported, using properties like sonar.jacoco.reportPaths, which you don’t seem to have defined here (which would explain why down the road you do not get coverage numbers imported in SonarQube).


(Classtest) #3

Thank you Nicolas for helping. I have tried with provided reference and used below properties, profiles but still unit test results are not displaying in sonarqube.

sonar.projectKey=devtest
sonar.projectName=devtest
sonar.sourceEncoding=UTF-8
sonar.sources=modules/war/src,modules/jar/src
sonar.java.source=modules/war/src,modules/jar/src
sonar.java.binaries=modules/jar/classes,modules/war/classes
sonar.junit.reportPaths=dist/test-reports
sonar.core.codeCoveragePlugin=jacoco
sonar.jacoco.reportPaths=dist/test-reports

I have done below setup for project in sonarqube.

Quality Gate

  • SonarQube way

Blocker Issues is greater than 0
Coverage on New Code Always is less than 80
Critical Issues is greater than 0
Duplicated Lines on New Code (%) Always is greater than 0
Open Issues is greater than
Reopened Issues is greater than 0
Skipped Unit Tests is greater than 0
Unit Test Duration is greater than
Unit Test Errors is greater than 0
Unit Test Failures is greater than 0
Unit Test Success (%) is greater than
Unit Tests is greater than

Quality Profiles

  • (CSS)
  • (Groovy)
  • (Java)
  • (JavaScript)
  • (Web)

Junit test reports are generating and able to publish in Jenkins but unable to import the Unit test results in SonarQube and not able to view.

Please let me know how to import unit test results in sonarqube. Does this supports only for java ?