Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 219
RRK Avatar asked Mar 18 '23 10:03

RRK


1 Answers

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>
like image 83
RRK Avatar answered May 01 '23 02:05

RRK