What is and how do we measure code coverage?

Test quality is very important and one of the most important things in building quality tests is to cover all production code lines with tests.

Code coverage is a metric that shows us the percentage of code that is covered by tests. Using test coverage we can also identify the lines of code that we missed.

intellij-code-coverage
Using IntelliJ Idea to check for code coverage

All modern IDEs have a tool that allows us to run tests with code coverage. This way we will be able to see what methods and lines of production code we didn’t cover and write more tests before pushing the code into a repository.

Another great way to check code coverage is to use a tool like SonarQube.

intellij-code-coverage-2
Covered lines are green and uncovered are red

Leave a Comment

Your email address will not be published. Required fields are marked *