What’s the Point of Code Coverage?

And does 100% coverage mean anything

Dan Goslen
Level Up Coding
Published in
5 min readJun 15, 2020

--

Photo by Federico Lancellotti on Unsplash

Code coverage is another one of those topics that tend to divide developers. Some developers and managers insist that 100% coverage is the standard. Others, especially thought-leaders, insists on a number somewhere between 80% and 90%.

So what is code coverage? And what, if anything, does it bring to your team?

Code Coverage is Just Another Measurement

Code coverage is just like every other quality control metric you might use to monitor the quality of your codebase. Its also probably the simplest.

While I won’t review every aspect of code coverage (line vs. branch vs. condition, etc.), coverage reports are telling you the percentage of code executed during your tests. Coverage gets collected by invoking your tests with a special agent or compilation flag that tracks the blocks of code executed while tests are running.

Each coverage tool works a little differently, but at the core, most of them either create an “agent” that performs instrumentation on your source (Jacoco and Coverage.py work this way) or by having access to internally generated files used for debugging to track what lines get hit.

Regardless of how they work internally, most coverage tools will generate a report in the form of an .html file and list the coverage for each package, class, etc. This report is where you find the overall percentage of coverage for your codebase. That number is then what you would use if asked by your manager, co-worker, or significant other (OK — probably not your significant other) what the code coverage is on a particular project.

Code Coverage Acts as a Validator

What code coverage tools do is validate that your tests are testing what you think they are. When we write tests (especially unit tests), we are often targeting a specific part of our code to verify. Code coverage can help us validate we are indeed testing the code we intend to.

It is this validation that makes code coverage a quality control mechanism for your codebase. If you have 100 tests in a test suite, but they all are executing the same code over and over, most of…

--

--

Jesus follower | Husband | Dad | Software engineer. Helping devs build better teams