Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube not picking up Unit Test Coverage

I am having issues with sonar picking up the jacoco analysis report. Jenkins however is able to pick up the report and display the results. My project is a maven build, built by Jenkins. The jacoco report is generated by maven (configured in the pom). Sonar is executed by using the Jenkins plugin.

This is what I see on SonarQube:

SonarQube Screen Capture

This is the report i can see of the project in jenkins.

Jacoco report in Jenkins

The maven plugin config:

<plugin>     <groupId>org.jacoco</groupId>     <artifactId>jacoco-maven-plugin</artifactId>     <version>0.6.4.201312101107</version>     <executions>       <execution>         <id>default-prepare-agent</id>         <goals>             <goal>prepare-agent</goal>         </goals>       </execution>       <execution>         <id>default-report</id>         <phase>prepare-package</phase>         <goals>             <goal>report</goal>         </goals>       </execution>       <execution>           <id>default-check</id>           <goals>               <goal>check</goal>           </goals>       </execution>     </executions> </plugin> 

Jenkins Sonar Plugin config enter image description here

like image 657
anton91 Avatar asked Mar 04 '14 14:03

anton91


People also ask

Why is SonarQube not picking up test coverage?

SonarQube doesn't run your tests or generate reports. It only imports pre-generated reports. It means that you have to provide the report generated from Jacoco to SonarQube (using sonar. coverage.

How do I get unit test coverage in SonarQube?

Build your project using MSBuild. Run your test tool, instructing it to produce a report at the same location specified earlier to the MSBuild SonarQube Runner (How to generate reports with different tools) Run the SonarScanner. MSBuild.exe end command.

How do I enable junit coverage in Sonar?

To enable coverage, you need to: Adjust your build process so that JaCoCo report generation step runs before the SonarScanner step. Make sure that JacCoCo writes its report file to a defined path in the build environment.

Does SonarQube provide test coverage?

SonarQube supports the reporting of test coverage information as part of the analysis of your . NET project. However, SonarQube does not generate the coverage report itself. Instead, you must set up a third-party tool to produce the report as part of your build process.


1 Answers

You were missing a few important sonar properties, Here is a sample from one of my builds:

sonar.jdbc.dialect=mssql sonar.projectKey=projectname sonar.projectName=Project Name sonar.projectVersion=1.0 sonar.sources=src sonar.language=java sonar.binaries=build/classes sonar.tests=junit sonar.dynamicAnalysis=reuseReports sonar.junit.reportsPath=build/test-reports sonar.java.coveragePlugin=jacoco sonar.jacoco.reportPath=build/test-reports/jacoco.exec 

The error in Jenkins console output can be pretty useful for getting code coverage to work.

Project coverage is set to 0% since there is no directories with classes.
Indicates that you have not set the Sonar.Binaries property correctly

No information about coverage per test
Indicates you have not set the Sonar.Tests property properly

Coverage information was not collected. Perhaps you forget to include debug information into compiled classes? Indicates that the sonar.binaries property was set correctly, but those files were not compiled in debug mode, and they need to be

like image 90
Cole9350 Avatar answered Sep 26 '22 02:09

Cole9350