Sonarqube:查看涵盖源代码的单元测试 [英] Sonarqube: view unit tests that cover the source

查看:354
本文介绍了Sonarqube:查看涵盖源代码的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Bamboo中有一个配置项设置,该配置项运行Junit测试并使用Jacoco计算单元测试覆盖率.然后,我们运行Sonar插件进行源代码分析.一切工作正常,我们可以在SonarCube服务器上看到分析,包括覆盖范围,但我们希望确切地看到哪些测试覆盖了某些代码行.现在它只是说:被单元测试覆盖.

We have a CI setup in Bamboo which runs Junit Tests and computes Unit Test Coverage using Jacoco. Then we run Sonar plugin for source code analysis. Everything is working great and we can see the analysis on the SonarCube server, inlcuding coverage, but we would like to see exactly which tests cover certain line of code. Right now it just says: covered by unit tests.

有没有办法做到这一点?

Is there a way to do that?

推荐答案

我在示例声纳项目中找到了答案:

I found an answer in the sample sonar project: https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/ut/ut-maven-jacoco.

必须为surefire插件配置Jacoco侦听器.

Jacoco listener has to be configured for surefire plugin.

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <!-- Minimal supported version is 2.4 -->
        <version>2.13</version>
        <configuration>
          <properties>
            <property>
              <name>listener</name>
              <value>org.sonar.java.jacoco.JUnitListener</value>
            </property>
          </properties>
        </configuration>
      </plugin>

并添加了依赖项:

   <dependency>
      <groupId>org.sonarsource.java</groupId>
      <artifactId>sonar-jacoco-listeners</artifactId>
      <version>3.8</version>
      <scope>test</scope>
    </dependency>

还需要声纳插件的以下参数的组合:

Also some combination of the following parameters for sonar plugin was needed:

sonar.java.surefire.reportspath 
sonar.junit.reportsPath
sonar.tests=src/test

最后一个完成了交易

这篇关于Sonarqube:查看涵盖源代码的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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