3
votes

I am running Sonar task through Ant, triggered by Jenkins in RHEL environment. I am successfully using Cobertura for Junit code coverage and Surefire for reporting. Sonar imports the Surefire reports fine.

However, now I am running Selenium tests using Ant in Jenkins. I would like to report code coverage and test results to Sonar. Apparently I need the JaCoCo plugin which analyses code coverage and reports tests. I presume like for unit tests, Jenkins does the job and Sonar only imports the reports into its own repository.

I am puzzled on how to actually do this. The web page http://www.sonarsource.org/measure-coverage-by-integration-tests-with-sonar-updated/ references to the JaCoCo page http://www.eclemma.org/jacoco/trunk/doc/ant.html. I am not sure what the steps are to be done. Do I need the coverage target? Should I only start the agent? Where in Ant do I start the agent? Do I need to dump stuff?

I really appreciate all the help I can get, thanks :)

1

1 Answers

4
votes

Sonar 3.3 has a new feature for combine code coverage metrics generated by both unit tests and integration tests. This is done by using two properties to detail the two different report files generated by the jacoco too:

#Tells Sonar where the unit tests code coverage report is
sonar.jacoco.reportPath=reports/jacoco/jacoco-ut.exec

#Tells Sonar where the integration tests code coverage report is
sonar.jacoco.itReportPath=reports/jacoco/jacoco-it.exec

The Sonar examples project has an integration test example for ANT:

Unfortunately it doesn't give an example of running the actual tests, instead it just shows how to configure an ANT build to load data.

Finally the Sonar documentation has more details with links to the example projects.