Configure Sonar 6.2 code coverage on a Maven project

Viewed 6546

I have pretty standard Maven multi-modules project (with JUnit, Arquillian and Selenium tests). I have Sonar 6.2 installed on a server. And on my project on Sonar the Code Coverage metric indicates 0.0%. But I know it's wrong as I do have some test coverage.

I found this Generic Test Data documentation page that explains that since 6.2 Sonar is supporting code coverage out of the box and that I have to pass a comma-delimited list of report paths to a parameter sonar.coverageReportPaths (I guess provided either in my pom or in command line).

I'm fine with that. But I cannot find out an example on how to setup this for a pretty classical Java project. What kind of file do I need to give in the list ? The relative paths to each of my Surefire/Failsafe reports ? Do I need to generate Jacoco reports in addition ? Can I give a "generic" path like report.xml if all of my reports have the same name ?

1 Answers

For standard Java project is it probably the easiest to use JaCoCo to generate coverage data and then feed it to SonarJava (SonarQube's plugin to analyze Java code). You can find documentation here https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project

You might find mentions of separation between unit tests and integration tests, this has been deprecated and now there is only single kind of coverage.

Don't hesitate to reach out to mailing list or ask question if something is not clear, we are in the process of improving this documentation.

Related