【问题标题】:How to include Unit and Integration test in Sonar Code Coverage如何在 Sonar 代码覆盖率中包含单元和集成测试
【发布时间】:2017-11-18 18:37:16
【问题描述】:

我正在使用以下命令来构建我的 maven 代码。

编译-

-DargLine="-DDB_SERVER=localhost -DDB_PORT=5432 -DDB_NAME=sample -DDB_USER=sample -DDB_PASSWORD=sample -DDB_MAX_POOL=10" -Dcom.sample.redis=false clean compiler:compile

单元测试分析-

DargLine=-DDB_SERVER=localhost -DDB_PORT=1234 -DDB_NAME=sample -DDB_USER=sample -DDB_PASSWORD=sample -DDB_MAX_POOL=10 -Dcom.sample.redis=false -Dcobertura:cobertura-integration-test -Dcobertura.aggregate=false -Dcobertura.report.format=xml integration-test test

并使用以下声纳属性来捕获要在声纳中发布的 xml。

sonar.projectKey=sample
sonar.projectName=sample
sonar.projectVersion=$PipelineId
sonar.modules=admin,client-api,common,om,serviceproviders
sonar.cobertura.reportPath=target/site/cobertura/coverage.xml
sonar.sources=.
sonar.skipPackageDesign=true
sonar.sourceEncoding=UTF-8

作为多模块,代码覆盖率仅显示 9.4%。我有什么遗漏吗。我也没有看到任何错误日志。如何使用 Jacoco 之类的覆盖工具实现相同的目标。

SonarQube - Version 5.1.1 - LGPL v3

【问题讨论】:

  • 当前版本为 6.4,当前 LTS 为 5.6.6。您不太可能为

标签: maven sonarqube jacoco cobertura jacoco-maven-plugin


【解决方案1】:

Maven 有一个生命周期Maven Lifecycle,其中每个目标都包括它之前的目标。例如“test”包含“compile”,“integration-test”包含“test”等。一般只需要在生命周期的末端包含目标即可。例如“mvn test”是指(编译并运行测试)。

我认为您想要运行“mvn verify”目标,即编译、运行测试和集成测试,然后运行验证(覆盖检查等)。 Cobertura 有一个插件,它应该与 maven 集成并利用各种目标在适当的时间运行它的部分。我猜你是通过拥有多个目标并试图将其分解成碎片来搞砸 cobertura - 即覆盖仪器或其他东西。

同样,您可能会发现使用 jacoco 比使用 cobertura 更容易。它隐藏了工具,并且与 maven 无缝集成。

祝你好运。

【讨论】:

  • 我怎样才能使用 Jacoco 覆盖工具达到同样的效果?
猜你喜欢
  • 2013-11-28
  • 2014-01-21
  • 2013-11-23
  • 2018-10-18
  • 1970-01-01
  • 1970-01-01
  • 2013-08-09
  • 2016-01-16
  • 2016-03-27
相关资源
最近更新 更多