sonarQube displaying code coverage 0% in scala

Viewed 1992

i am using sonarQube-8.5.1.38104 and i am using it in my scala project and followed this link here is my plugins.sbt file

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")

addSbtPlugin("com.github.mwz" % "sbt-sonar" % "2.2.0")

and here is my build.sbt file

import sbtsonar.SonarPlugin.autoImport.sonarUseExternalConfig

coverageEnabled := true

sonarProperties ++= Map(
  "sonar.host.url" -> "http://127.0.0.1:9000",
  "sonar.projectName" -> "myproject-backend",
  "sonar.projectKey" -> "sonar-myproject-backend",
  "sonar.sources" -> "src/main/scala-2.13",
  "sonar.tests" -> "src/test/scala-2.13",
  "sonar.junit.reportPaths" -> "target/test-reports",
  "sonar.sourceEncoding" -> "UTF-8",
  "sonar.scala.scoverage.reportPath"->"target/scala-2.13/scoverage-report/scoverage.xml",
  "sonar.scala.scapegoat.reportPath" -> "target/scala-2.13/scapegoat-report/scapegoat.xml"
)

followed sbt-scoverage

then i did -> sbt -> coverage -> test -> coverageReport generated the report

[info] Written Cobertura report [/home/user/git/myproject/target/scala-2.13/coverage-report/cobertura.xml]
[info] Written XML coverage report [/home/user/git/myproject/target/scala-2.13/scoverage-report/scoverage.xml]
[info] Written HTML coverage report [/home/user/git/myproject/target/scala-2.13/scoverage-report/index.html]
[info] Statement coverage.: 38.67%
[info] Branch coverage....: 31.58%

then i did

sonarScan

and check the report at http://127.0.0.1:9000/dashboard?id=myproject-backend

then code coverage is displayed 0.0% and Unit tests -

and i have checked the reports exists at

target/scala-2.13/scoverage-report/scoverage.xml
target/scala-2.13/scapegoat-report/scapegoat.xml

and class test reports exists at

target/test-reports

com.myproject.test.abctest.EventTest.xml               com.myproject.test.xyztest.FileUploadTest.xml  TEST-com.myproject.test.xyztest.DirectoryCreationTest.xml
com.myproject.test.abctest.QueryEventTest.xml                TEST-com.myproject.test.abctest.InsertEventTest.xml   TEST-com.myproject.test.xyztest.FileUploadTest.xml
com.myproject.test.xyztest.DirectoryCreationTest.xml  TEST-com.myproject.test.abctest.QueryEventTest.xml

why i am getting code coverage 0% then ? what am i missing here ? please guide ,thanks

2 Answers

I was giving the wrong key the correct key was

"sonar.scala.coverage.reportPaths"->"target/scala-2.13/scoverage-report/scoverage.xml",
"sonar.scala.scapegoat.reportPaths" -> "target/scala-2.13/scapegoat-report/scapegoat-scalastyle.xml"

after that I am able to get the code coverage % but unit tests count was still missing because I think its not supported by sonar right now here scala is not mentioned in test execution https://docs.sonarqube.org/latest/analysis/coverage/

Thanks @swaheed, I can't add a comment to your post due to reputation limit.

We also come across this problem when using sonar-scala. We found that the code coverage can be showed with the below properties:

For SonarQube Version 8.6: needs to use sonar.scala.coverage.reportPaths as @swaheed mentioned.

"sonar.scala.coverage.reportPaths"->"target/scala-2.13/scoverage-report/scoverage.xml"

For SonarQube Version 8.7.1 Community (I follow this docker-compose to bring up the SonarQubeDocker https://github.com/sonar-scala/sonar-scala-docker/blob/master/docker-compose.yml), either of the properties below works

"sonar.scala.coverage.reportPaths"->"target/scala-2.13/scoverage-report/scoverage.xml"

or

"sonar.scala.scoverage.reportPath"->"target/scala-2.13/scoverage-report/scoverage.xml"

Related