0
votes

I am trying to calculate code coverage for both my Unit tests & Functional tests. After running my unit tests i generate jacoco.exec file. Similarly for functional tests i get jacoco-it.exec file.

Now i want to provide these files as input to sonar as below:

mvn sonar:sonar -Dsonar.jdbc.url="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" -Dsonar.jdbc.username=sonar -Dsonar.jdbc.password=sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.jacoco.reportPath=jacoco.exec -Dsonar.jacoco.itReportPath=jacoco-it.exec

But sonar generates 0% coverage at dashboard. Is there any other way i can calculate the coverage from jacoco.exec files, without providing my source code/ binaries to analyse it?

1

1 Answers

0
votes

What is the configuration of jacoco in your pom.xml ?

Have you check the path of you report ?

The sample code from sonarqube showing how to have UT, IT and coverage using Jacoco: http://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Integration+Tests+for+Java+Project

https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco

And I think setting properties in pom.xml is better than use -D parameter ...

<properties>
    <!-- select JaCoCo as a coverage tool -->
    <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
    <!-- force sonar to reuse reports generated during build cycle -->
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <!-- set path for unit tests reports -->
    <sonar.jacoco.reportPath>${project.basedir}/target/jacoco-unit.exec</sonar.jacoco.reportPath>
    <!-- all modules have to use the same integration tests report file -->
    <sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
</properties>