annedroiid annedroiid - 7 months ago 73
Java Question

Can't get Unit Test Success in SonarQube

I can't figure out how to get the "Unit Test SUccess" section to appear on my SonarQube dashboard. I've tried setting every sonar and I can think of but they just don't appear. I am using the "sbt-sonarrunner-plugin", version 1.0.4, and Jacoco for calculating coverage. Any help would be greatly appreciated, as everything I have found says that settings the sonar.junit.reportsPath property should make it work. For reference I have also tried setting the sonar.test property and it didn't work either.

This is what the unit test widget looks like.

enter image description here

Here are my properties, the project name and directory are passed in.

val commonSonarProperties = Map(
"sonar.projectName" -> s"$projectName",
"sonar.junit.reportsPath" -> s"$projectDir/target/test-reports",
s"$projectName.sonar.sources" -> s"$projectDir/src/main/java",
"" -> s"$projectDir/target/classes",
"" -> s"$projectDir/src/test/java",
"" -> s"$projectDir/target/test-classes",
"" -> "jacoco",
"sonar.jacoco.reportPath" -> s"$projectDir/target/jacoco/jacoco.exec",
"sonar.jacoco.itReportPath" -> s"$projectDir/target/it-jacoco/jacoco.exec"


I figured out what was going wrong. I noticed in the logs when I ran Sonar with log level set to debug I was getting the following message.

- parsing <directory>/target/test-reports
- Reports path contains no files matching TEST-.*.xml : <directory>/target/test-reports

I had set my "sonar.junit.reportsPath" correctly, but Sonar was expecting the xml files in my directory to start with "TEST-". When I renamed the xml files to start with TEST- the results then displayed on the dashboard.