Sunday, April 5, 2020

JaCoCo Code Coverage Configuration

Generate Code Coverage with JaCoCo and spring boot maven plugin.

Add below plugin in pom.xml
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
   <!-- Jaccoc -->
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M4</version>
    <executions>
     <execution>
      <goals>
       <goal>integration-test</goal>
       <goal>verify</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
   <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.5</version>
    <executions>
     <execution>
      <id>default-prepare-agent</id>
      <goals>
       <goal>prepare-agent</goal>
      </goals>
     </execution>
     <execution>
      <id>default-report</id>
      <phase>verify</phase>
      <goals>
       <goal>report</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
Execute command:
mvn clean install
Code coverage Report:-

you can find Jacoco reports in c:\workspace\project_name\target\site\jacoco\index.html
Open index.xml in any browser.
Report will looks like below.

No comments:

Post a Comment