Integrating JaCoCo

Let's integrate JaCoCo into our existing project:

  1. First, include the plugin that includes JaCoCo in the POM file:
<plugin> 
   <groupId>org.jacoco</groupId> 
   <artifactId>jacoco-maven-plugin</artifactId> 
   <version>0.7.9</version> 
</plugin> 
The second and third step is to include pre-executions and post-executions into the preceding plugin.
  1. The pre-execution prepares the agent to be configured and added to the command line.
  2. The post-execution ensures that the reports get created in the output folders:
<executions> <execution> <id>pre-unit-test</id> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> <propertyName>surefireArgLine</propertyName> ...

Get Cloud-Native Applications in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.