【问题标题】:sonar coverage reports for multiple java unit test reports多个 java 单元测试报告的声纳覆盖率报告
【发布时间】:2016-08-04 22:31:07
【问题描述】:

我有一个名为 Customer 的 java 项目,在这个项目下我还有另外 8 个模块,这 5 个模块中有 junit 测试类,并且每个模块都有单独的 ant 构建文件。我已经为每个项目创建(生成了单元测试报告)jacoco.exec,现在,我喜欢将这 5 个模块的单元测试报告合并到一个报告中,并在 sona 覆盖部分中明智地显示(或)显示每个模块的单元测试报告。您能否为此提供任何建议。

谢谢, 约瑟夫

【问题讨论】:

    标签: unit-testing sonarqube sonarqube-scan


    【解决方案1】:

    您要做的是阅读每个模块的测试报告。您可以通过多模块项目配置来做到这一点。如果您从主 build.xml 处理所有内容,这可能是最直接的。我没有在 Ant 上测试过这个,但是这样的东西应该可以工作

    <property name="sonar.projectKey" ...
    <!-- all normal properties here -->
    <property name="sonar.modules" value="module1,module2..." />
    <property name="module1.sonar.jacoco.reportPath" value="...
    

    请注意,如果 Jacoco 报告都位于标准位置,您甚至可能不需要指定它们,因为子模块继承其父模块的属性。 The docs 用于多模块项目配置的编写时并未考虑到 Ant 语法,但只要您从 SonarQube Scanner for Ant docs 中牢记这一点,您就应该能够解决这个问题:

    SonarQube Scanner for Ant 是一个 Ant 任务,它是 SonarQube Scanner 的包装器,它通过调用 SonarQube Scanner 并将所有按照 sonar.* 约定命名的属性传递给它。这样做的缺点是不是非常 Ant-y,但优点是可以即时提供由新版本插件或 SonarQube 本身引入的任何新分析参数。

    【讨论】:

    • 非常感谢安,我会试试你上面提到的“module1.sonar.jacco.reportPath”等等......
    • 现在,我收到此错误,当我在 jenkins 中使用 sonar-runner 运行我的项目时,错误:原因:无法加载组件类 org.sonar.batch.repository.ProjectRepositories 错误:导致作者:localhost:9000/batch/… 上的错误 500
    • 您最好将其带到 Google 群组:groups.google.com/forum/#!forum/sonarqube
    • 当然,谢谢 Ann.. 我之前的问题得到了解决,因为您建议为每个子项目设置模块名称...
    【解决方案2】:

    非常感谢。再次对安..它对我有用,在为 sonar-project.properties 中的每个子项目添加单独的模块后解决了我的问题(每个模块的覆盖范围和多种语言),如下所述.. 在 Sonarqube 中获取模块的“覆盖”结果..

    # Modules
    sonar.modules=common,help,mobile,partners
    
    common.sonar.projectBaseDir=C:/dev/workspaces/hg/customer
    common.sonar.sources=common/src/main/java,common/web
    common.sonar.tests=common/src/test/java
    common.sonar.binaries=common/bin
    common.sonar.junit.reportsPath=common/test/reports/junitreport   
    common.sonar.surefire.reportsPath=common/test/reports/junitreport
    common.sonar.jacoco.reportPath=common/coverage/common.exec
    
    help.sonar.projectBaseDir=C:/dev/workspaces/hg/customer
    help.sonar.sources=help/src/main/java,help/web
    help.sonar.tests=help/src/test/java
    help.sonar.binaries=help/bin
    help.sonar.junit.reportsPath=help/test/reports/junitreport   
    help.sonar.surefire.reportsPath=help/test/reports/junitreport
    help.sonar.jacoco.reportPath=help/coverage/help.exec
    

    【讨论】:

    【解决方案3】:

    这对我有用:

    sonar.modules=common,help
    sonar.sources=./src/main/java
    sonar.binaries=./target/classes
    sonar.tests=./src/test/java
    sonar.junit.reportsPath=./target/surefire-reports
    

    路径应该是相对的,因为声纳会自动导航到 basedir/module_name/target/surefire-reports

    【讨论】:

      猜你喜欢
      • 2019-11-01
      • 2017-10-25
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      • 2013-09-26
      • 2017-02-11
      • 2012-07-18
      • 2017-03-23
      相关资源
      最近更新 更多