I\'m using JaCoCo for Code Coverage. The Unit Test reports are created with junit and they are imported correctly, so that the unit test information is shown properly. The <
Have you tried using the prepare-agent
?
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install
Also, if your coverage keeps showing 0%, you might need to follow this advice:
If your project already uses the argLine to configure the surefire-maven-plugin, be sure that argLine defined as a property, rather than as part of the plugin configuration."
In my case below commands works.
mvn clean org.jacoco:jacoco-maven-plugin:0.7.3.201502191951:prepare-agent install
mvn sonar:sonar
To check code coverage: Start SonarQube server -> Run above two commands one after another & you will see code coverage in SonarQube Client.
FYI: My SonarQube Version - 5.1.2. You can download latest version from SonarQube Download
I use JUnit as well and in my case the issue was because of having TestNG dependency in my pom.xml. After removing this unnecessary dependency, everything started to work as expected.
With this Maven configuration I am able to see coverage per test data.
You need to configure sonar-jacoco-listeners to get coverage per test.
Please be aware that it is deprecated by sonar: "this feature is deprecated at SonarQube level and will no longer receive further improvements/maintenance."
<skipTests>false</skipTests>
<!--Jacoco settings -->
<jacoco.haltOnFailure>false</jacoco.haltOnFailure>
<jacoco.skip>false</jacoco.skip>
<!-- sonar JACOCO properties -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${project.reporting.outputDirectory}/jacoco-ut.exec</sonar.jacoco.reportPaths>
<sonar.language>java</sonar.language>
<!-- Added for Jacoco -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<destFile>${sonar.jacoco.reportPaths}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.8.1</version>
<classifier>runtime</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>