Cannot view the coverage percentage in SonarQube metrics

1,832 views
Skip to first unread message

shaad47

unread,
Apr 25, 2018, 11:24:53 AM4/25/18
to SonarQube
Hi all,

 I am using SonarQube v6.7.2 with Jenkins 2.89.4 and Maven 3.0.2.

I launched the SonarQube analysis with the following configurations:

POM.xml

            <!--Plugin to lauch unit and integration tests-->
            <plugin>
                <!-- Separates the unit tests from the integration tests. -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                   <!-- Skip the default running of this plug-in (or everything is run twice...see below) -->
                    <skip>true</skip>
                   <!-- Show 100% of the lines from the stack trace (doesn't work) -->
                    <trimStackTrace>false</trimStackTrace>
                </configuration>
                <executions>
                    <execution>
                        <id>unit-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <argLine>${jacoco.agent.ut.arg}</argLine>
                            <!-- Never skip running the tests when the test phase is invoked -->
                            <skip>false</skip>
                            <includes>
                                <!-- Include unit tests within integration-test phase. -->
                                <include>**/*Test.java</include>
                            </includes>
                            <excludes>
                            <!-- Exclude integration tests within (unit) test phase. -->
                                <exclude>**/*IT.java</exclude>
                            </excludes>
                            <properties>
                                <property>
                                    <name>listener</name>
                                    <value>org.sonar.java.jacoco.JUnitListener</value>
                                </property>
                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
           
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <includes>
                        <include>**/*/TestSuiteInt.java</include>
                    </includes>
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m ${jacoco.agent.it.arg}</argLine>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>org.sonar.java.jacoco.JUnitListener</value>
                        </property>
                    </properties>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit4</artifactId>
                        <version>2.7</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>integration-tests</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <argLine>-Xmx1024m -XX:MaxPermSize=256m ${jacoco.agent.it.arg}</argLine>
                            <properties>
                                <property>
                                    <name>listener</name>
                                    <value>org.sonar.java.jacoco.JUnitListener</value>
                                </property>
                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.2.201409121644</version>
                <executions>
                    <!-- Prepares a variable, jacoco.agent.ut.arg, that contains the info
                        to be passed to the JVM hosting the code being tested. -->
                    <execution>
                        <id>prepare-ut-agent</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                            <propertyName>jacoco.agent.ut.arg</propertyName>
                            <append>true</append>
                        </configuration>
                    </execution>
                    <!-- Prepares a variable, jacoco.agent.it.arg, that contains the info
                        to be passed to the JVM hosting the code being tested. -->
                    <execution>
                        <id>prepare-it-agent</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.itReportPath}</destFile>
                            <propertyName>jacoco.agent.it.arg</propertyName>
                            <append>true</append>
                        </configuration>
                    </execution>
                    <execution>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

           <dependencies>       
               <dependency>
                    <groupId>org.codehaus.sonar-plugins.java</groupId>
                    <artifactId>sonar-jacoco-listeners</artifactId>
                    <version>1.4</version>
                    <scope>test</scope>
               </dependency>
          </dependencies>

Jenkins configuration for Sonar:

# unique project identifier (required)
sonar.projectKey=ADNCore

# project metadata (used to be required, optional since SonarQube 6.1)
sonar.projectName=ADNCore
sonar.projectVersion=4.0.0

# path to source directories (required)
sonar.sources=src_adnAccountController,src_adnCommon,src_adnDbRepresentation,src_adnException,src_adnFilters,src_adnGenericDao,src_adnKCM,src_adnKnowledgeIndex,src_adnLogging,src_adnNotifications,src_adnRightsAccess,src_adnWebServices,src_aspect_ordering,src_cmd,src_conflicts,src_excel,src_export,src_hbSessionOnDemand,src_KBEConnector,src_licensing,src_rightsAccessCheck,src_validation


# path to test source directories (optional)
sonar.tests=src/test/java


# path to Java project compiled classes (optional)
sonar.java.binaries=target/classes

#path to libraries
sonar.java.libraries=target/ADNCore/WEB-INF/lib/**.jar

sonar.test.inclusions=target/test-classes/

#path to reports
sonar.junit.reportPaths=target/failsafe-reports/**.xml

#Path to Jacoco reports
sonar.jacoco.reportPaths=target/jacoco-it.exec

With these configurations, I have all metrics on the SonarQube server, but the coverage percentage is always 0%. I have around 120 tests in my project and all tests are successfully launched and respecting reports were also created. I see that jacoco-it.exec file is also created with some data in it. And also, I see no error or warnings in any of the logs. But I still cannot see the coverage percentage in sonarqube server.

I would be grateful, if anyone could guide me this please?

Thanks in advance,

SD


G. Ann Campbell

unread,
Apr 25, 2018, 1:58:52 PM4/25/18
to SonarQube
Hi,

It's difficult to say what's going on without the relevant excerpts from your analysis log, but a couple things do catch my eye.

* You're pointing sonar.test.inclusions to class files, not source files. That's probably not the cause of the problem, but it can't be helping.
* You really don't need to specify sonar.test.inclusions
* You're building with Maven. Why analyze with the vanilla SonarQube scanner? You should be running a Maven analysis, Jenkins or not. Maven will already know where your test files (and source files, and libraries) are and automatically pass them into the analysis (ditto your test reports).


Ann

Shaad47

unread,
Apr 27, 2018, 3:31:11 AM4/27/18
to SonarQube
Hi Ann,

Thank you for your response.

The point of adding sonar.test.inclusions was because I was getting a warning saying "Execution data for class doesnot match".

I even tried runner "mvn sonar:sonar" command, yet still the coverage is 0%.

regards,
SD

clark...@gmail.com

unread,
Apr 27, 2018, 4:01:20 AM4/27/18
to SonarQube
Hi,

can you please clarify if the coverage is not showing, or if it says it is 0%? you're kind of saying both things in your description.
also are you talking absolute coverage, or coverage on new code only?

FYI, it took my SonarQube server a few analysis to show expected numbers on our projects. You may want to run a few more analysis.
Also, I noticed enabling SCM sensor on a project can help. (Project > Admin > SCM > SCM Sensor > Enable).

Regards,
Gabriel.

Shaad47

unread,
Apr 27, 2018, 4:21:03 AM4/27/18
to SonarQube
Hi,

Thank you for yorur response.

Yes, the absolute coverage data is 0%. Perhaps I have 120 tests included and all run successfully. And also, failsafe reports and jacoco.exec files are successfully generated, yet still the percentage of the coverage is 0%.

And SCM sensor was also enabled for all my analysis.

I have attached my build log, could you please have a look at it?

Regards,
SD
sonar-analysis-log.txt

clark...@gmail.com

unread,
Apr 27, 2018, 6:26:16 AM4/27/18
to SonarQube
I don't see sonar execution in your log and I don't see sonar plugin configuration in your pom.xml.
Can you confirm everything is set as documented here: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven and tell us what men command line you are executing?

and also:
 - do you see all the analysis in SonarQube server?

Regards,
Gabriel.

Shaad47

unread,
Apr 27, 2018, 6:47:07 AM4/27/18
to SonarQube
Sorry here is the log for sonar analysis.

And yes I have configured everything as per the document.

I have added the plugins and its dependencies. I used "mvn sonar:sonar command to launch the analysis. And I could all see all other data of the analysis on the sonarqube server except coverage.

Could be the problem related to jacoco plugin?

Regards,
SD
sonar-analysis-log.txt

clark...@gmail.com

unread,
Apr 27, 2018, 7:34:54 AM4/27/18
to SonarQube
Shaad,

in your maven logs I can see:
  1. clean
  2. compile
  3. surefire plugin and test execution
  4. war packaging
  5. more tests (seem to be API tests)
  6. reports creation
  7. build success
and no traces of any SonarQube analysis. I've not read maven logs for a long time, but I'm pretty much sure about that.
What I would do is run an analysis using sonar-scanner first (you can tell in parameters where Jacobo report is). And when you get things work, try to integrate into maven.

Good luck!

Gabriel

Shaad47

unread,
Apr 27, 2018, 8:56:34 AM4/27/18
to SonarQube
I am really Sorry for the wrong log file.

Now I have tried with SonarQube Scanner and still the coverage results are same.

Here are the sonar.project.properties:


# unique project identifier (required)
sonar.projectKey=ADNCore

# project metadata (used to be required, optional since SonarQube 6.1)
sonar.projectName=ADNCore
sonar.projectVersion=4.0.0

# path to source directories (required)
sonar.sources=src_adnAccountController,src_adnCommon,src_adnDbRepresentation,src_adnException,src_adnFilters,src_adnGenericDao,src_adnKCM,src_adnKnowledgeIndex,src_adnLogging,src_adnNotifications,src_adnRightsAccess,src_adnWebServices,src_aspect_ordering,src_cmd,src_conflicts,src_excel,src_export,src_hbSessionOnDemand,src_KBEConnector,src_licensing,src_rightsAccessCheck,src_validation


# path to test source directories (optional)
sonar.tests=src/test/java


# path to Java project compiled classes (optional)
sonar.java.binaries=target/classes

#path to libraries
sonar.java.libraries=target/ADNCore/WEB-INF/lib/**.jar

#path to reports
sonar.junit.reportPaths=target/failsafe-reports/**.xml

#Path to Jacoco reports
sonar.jacoco.reportPaths=target/jacoco-it.exec

And I also attached the log file of the analysis with sonarqube scanner here: https://drive.google.com/open?id=16PxJaDt3zQS92tHUT_PLLNskEhv9GIxT. Could you please have a look?

Regards,
SD
Reply all
Reply to author
Forward
0 new messages