Code coverage testing
We previously implemented integration tests in our project, but we need to know whether they are enough or how much of our code they test. Now, we will learn about code coverage testing.
What is code coverage testing?
Code coverage testing is a metric used in software testing to measure how much of the source code is executed during testing. The purpose of code coverage testing is to identify untested parts of the code base and ensure that as much code as possible is covered by tests.
Implementing code coverage testing
We can use a library such as JaCoCo to implement code coverage testing in our project. JaCoCo integrates well with building tools such as Maven. Let’s add the JaCoCo plugin to the pom.xml
file:
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.12</version> <executions...