Monday, September 24, 2018

How to enable code coverage report using JaCoCo plug-in - Code coverage Report using JaCoCo, Maven and Jenkins - Code Coverage in Pipeline

Code coverage is important aspect for maintaining quality in Agile development. There are different ways to manage code quality. one of the effective ways is to measure code coverage by using plug-ins such as JaCoCo, Cobertura.

We will see how to enable code coverage for your Java project and view coverage report in Jenkins UI.

step # 1: Add Maven JaCoCo plugin in POM.xml under MyWebApp in bitbucket Repo

<build>
<finalName>MyWebApp</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>




Step 2 : Add JaCoCo plug-in in Jenkins:


Step 3:

For Freestyle Job:
Enable in Jenkins job to view code coverage report by going to post build action and add Record JaCoCo coverage report


For Pipelines:
Add below code in your existing pipeline:

stage ('Code coverage') {
jacoco()
}

Step 4 : Run the job by clicking Build now

Step 5:
 Click on the job to view code coverage report.

No comments:

Post a Comment