SonarQube 4.4 not displaying cobertura unit tests or code coverage for grails 2.4.3 with spock tests

China☆狼群 提交于 2019-12-10 17:12:06

问题


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.

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

target/test-reports/cobertura/coverage.xml

And I have

sonar.groovy.cobertura.reportPath

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

Running

mvn sonar:sonar (maven version 3.2.3)

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.

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

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>

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


回答1:


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>


来源:https://stackoverflow.com/questions/25901059/sonarqube-4-4-not-displaying-cobertura-unit-tests-or-code-coverage-for-grails-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!