From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Create a test coverage report with JaCoCo

Create a test coverage report with JaCoCo

- [Instructor] One way to ensure your code functions as intended is through comprehensive test coverage. In Java, one way to guarantee a test coverage percentage is with JaCoCo. JaCoCo stands for Java Code Coverage, and it's a plugin we seamlessly add to our Maven build configuration. Let's add it to this application. We'll go to our POM file and add a new plugin. The group ID will be org.jacoco. The artifact ID will be jacoco-maven-plugin, and the version will be 0.8.12. JaCoCo is a popular code coverage library for Java, and this plugin integrates it with Maven. Then we'll add an execution section. This will contain configurations that define when and how the plugin goals are executed during the build lifecycle. The prepare-agent goal sets up the JaCoCo Java Agent to collect coverage data during the test phase. This setup is necessary for JaCoCo to monitor the code coverage of your tests. We'll also add a second execution for the test phase. This goal generates the coverage report…

Contents