简体   繁体   中英

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 sonar.java 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.

在此处输入图片说明

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",
    "sonar.java.binaries" -> s"$projectDir/target/classes",
    "sonar.java.test" -> s"$projectDir/src/test/java",
    "sonar.java.test.binaries" -> s"$projectDir/target/test-classes",
    "sonar.java.coveragePlugin" -> "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.

I had the similar problem, where jenkins wasn't able to read the .exec file of jacoco. Upon checking sonar-project.properties i found that these two fields were empty:

sonar.junit.reportsPath=
sonar.jacoco.reportPath=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM