SonarQube 没有获得单元测试覆盖率 [英] SonarQube not picking up Unit Test Coverage

查看:44
本文介绍了SonarQube 没有获得单元测试覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在声纳接收 jacoco 分析报告时遇到问题.然而詹金斯能够拿起报告并显示结果.我的项目是一个 Maven 构建,由 Jenkins 构建.jacoco 报告由 maven 生成(在 pom 中配置).Sonar 使用 Jenkins 插件执行.

I am having issues with sonar picking up the jacoco analysis report. Jenkins however is able to pick up the report and display the results. My project is a maven build, built by Jenkins. The jacoco report is generated by maven (configured in the pom). Sonar is executed by using the Jenkins plugin.

这是我在 SonarQube 上看到的:

This is what I see on SonarQube:

这是我在 jenkins 中看到的项目报告.

This is the report i can see of the project in jenkins.

maven 插件配置:

The maven plugin config:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.6.4.201312101107</version>
    <executions>
      <execution>
        <id>default-prepare-agent</id>
        <goals>
            <goal>prepare-agent</goal>
        </goals>
      </execution>
      <execution>
        <id>default-report</id>
        <phase>prepare-package</phase>
        <goals>
            <goal>report</goal>
        </goals>
      </execution>
      <execution>
          <id>default-check</id>
          <goals>
              <goal>check</goal>
          </goals>
      </execution>
    </executions>
</plugin>

Jenkins 声纳插件配置

Jenkins Sonar Plugin config

推荐答案

您遗漏了一些重要的声纳属性,以下是我的一个构建示例:

You were missing a few important sonar properties, Here is a sample from one of my builds:

sonar.jdbc.dialect=mssql
sonar.projectKey=projectname
sonar.projectName=Project Name
sonar.projectVersion=1.0
sonar.sources=src
sonar.language=java
sonar.binaries=build/classes
sonar.tests=junit
sonar.dynamicAnalysis=reuseReports
sonar.junit.reportsPath=build/test-reports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=build/test-reports/jacoco.exec

Jenkins 控制台输出中的错误对于让代码覆盖率工作非常有用.

The error in Jenkins console output can be pretty useful for getting code coverage to work.

项目覆盖率设置为 0%,因为没有包含类的目录.
表示您没有正确设置 Sonar.Binaries 属性

Project coverage is set to 0% since there is no directories with classes.
Indicates that you have not set the Sonar.Binaries property correctly

没有关于每个测试的覆盖率的信息
表示您没有正确设置 Sonar.Tests 属性

No information about coverage per test
Indicates you have not set the Sonar.Tests property properly

未收集覆盖信息.也许你忘记在编译的类中包含调试信息? 表示 sonar.binaries 属性设置正确,但那些文件不是在调试模式下编译的,它们需要

Coverage information was not collected. Perhaps you forget to include debug information into compiled classes? Indicates that the sonar.binaries property was set correctly, but those files were not compiled in debug mode, and they need to be

这篇关于SonarQube 没有获得单元测试覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆