我正在使用
sonarQube-8.5.1.38104
并且我在我的 scala 项目中使用它并遵循这个 link
这是我的plugins.sbt
文件
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.github.mwz" % "sbt-sonar" % "2.2.0")
这是我的
build.sbt
文件
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"
)
已关注 sbt-scoverage
然后我就这么做了 ->
sbt
-> coverage
-> test
-> coverageReport
生成报告
[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%
然后我就这么做了
sonarScan
并在 http://127.0.0.1:9000/dashboard?id=myproject-backend
查看报告然后显示代码覆盖率0.0%和单元测试-
我已经检查了报告存在于
target/scala-2.13/scoverage-report/scoverage.xml
target/scala-2.13/scapegoat-report/scapegoat.xml
并且班级测试报告位于
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
为什么我的代码覆盖率是 0%?我在这里缺少什么?请指导,谢谢
我给错了钥匙 正确的键是
"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"
之后我可以获得代码覆盖率%,但单元测试计数仍然丢失,因为我认为现在声纳不支持它,这里在测试执行中没有提到scala https://docs.sonarqube.org/latest/analysis/coverage/
谢谢@swaheed, 由于声誉限制,我无法向您的帖子添加评论。
我们在使用sonar-scala时也遇到了这个问题。我们发现代码覆盖率可以通过以下属性来显示:
对于 SonarQube 版本 8.6:需要使用 sonar.scala.coverage.reportPaths 正如 @swaheed 提到的。
“sonar.scala.coverage.reportPaths”->“target/scala-2.13/scoverage-report/scoverage.xml”
对于 SonarQube 版本 8.7.1 社区(我按照这个 docker-compose 来启动 SonarQubeDocker https://github.com/sonar-scala/sonar-scala-docker/blob/master/docker-compose.yml) ,以下任一属性都有效
“sonar.scala.coverage.reportPaths”->“target/scala-2.13/scoverage-report/scoverage.xml”
或
“sonar.scala.scoverage.reportPath”->“target/scala-2.13/scoverage-report/scoverage.xml”
对我来说,在我更新到最新的插件版本+更新一些声纳库属性后,它可以工作。
即在project/plugins.sbt中添加:
libraryDependencies += "org.scoverage" % "sbt-scoverage_2.12_1.0" % "2.2.0"
我还需要以下声纳属性: