SonarQube 4.4在Spock测试中不显示cobertura单元测试或grails 2.4.3的代码覆盖率 [英] SonarQube 4.4 not displaying cobertura unit tests or code coverage for grails 2.4.3 with spock tests

查看:186
本文介绍了SonarQube 4.4在Spock测试中不显示cobertura单元测试或grails 2.4.3的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器上安装了SonarQube 4.4.我正在尝试为使用Spock框架编写的测试的grails(2.4.3)项目生成指标.但是,声纳不会显示单元测试结果或单元测试范围.

I have SonarQube 4.4 installed on my machine. I am trying to generate metrics for a grails (2.4.3) project that has tests written in Spock framework. However, sonar does not show unit tests results or unit tests coverage.

我验证了在下面提供的路径中生成了cobertura coverage.xml

I verified that cobertura coverage.xml gets generated in the path provided below

target/test-reports/cobertura/coverage.xml

target/test-reports/cobertura/coverage.xml

我有

sonar.groovy.cobertura.reportPath

sonar.groovy.cobertura.reportPath

我的pom.xml中的属性映射到上述路径.

property in my pom.xml mapped to the above path.

跑步

mvn sonar:sonar (maven version 3.2.3)

此项目上的

成功完成,并且控制台日志显示正在解析的coverage.xml.

on this project completes successfully and the console log shows the coverage.xml being parsed.

但是,当我在声纳中查看项目时,我只会看到静态代码分析指标,而没有单元测试或单元测试覆盖率.

However when I view the project in sonar, I only see the static code analysis metrics but no unit tests or unit tests coverage.

我还尝试使用声纳运行器运行分析并获得相同的结果.

I also tried to run the analysis using sonar-runner and get the same result.

我尝试了sonar-groovy-plugin(版本:0.5、0.6和1.0.1)和sonar-cobertura-plugin-1.6.3

I tried sonar-groovy-plugin (versions: 0.5, 0.6, and 1.0.1) and sonar-cobertura-plugin-1.6.3

这是pom.xml构建部分,用于运行groovy spock测试

Here is the pom.xml build section to run the groovy spock tests

<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
    <grailsVersion>${grails.version}</grailsVersion>
    <fork>false</fork>
</configuration>
<extensions>true</extensions>
<executions>
    <execution>
        <id>grails-tests</id>
        <phase>test</phase>
        <goals>
            <goal>exec</goal>
        </goals>
        <configuration>
            <command>test-app</command>
            <args>--unit:spock</args>
        </configuration>
    </execution>
</executions>
</plugin>

有人使用类似的配置,并且能够使用sonarqube和cobertura生成代码覆盖率指标吗?

Anyone used a similar configuration and able to generate code coverage metrics using sonarqube and cobertura?

推荐答案

对于其他面临类似问题的人,这里是解决方案.事实证明,我们需要在pom.xml中设置"sonar.sources"属性以显示覆盖范围.这是示例(您需要指定单个目录)

For anyone else facing a similar problem, here is the solution. It turns out we need to set the "sonar.sources" property in the pom.xml for coverage to show up. Here is the sample (you need to specify the individual directories)

<sonar.sources>src/java,src/groovy,grails-app/services,grails-app/controllers,grails-app/domain,grails-app/jobs</sonar.sources>

这篇关于SonarQube 4.4在Spock测试中不显示cobertura单元测试或grails 2.4.3的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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