Konubinix' opinionated web of thoughts

Code Coverage


Code coverage is the indicator that tells how much lines of code have been seen in the tests.

Code coverage is often seen in testing, and whether you run dedicated programs to test your code (like pytest) or you run your application (like ./myapp.py) don’t matter, provided you end up with confidence that you tried corner cases of your application and that lines got executed in those situations.

Reading a code coverage is solving an inverse problem. You don’t care about the code coverage per se. You are interested in the quality of the code, and the code coverage, although not very good, is the best indicator we could find to find out whether we considered all the code in the tests.

Therefore, I would discourage saying “I need to fix the code coverage” or “I need to have a code coverage to X%”, because that would put you in the state of mind of making an objective out of the measure (Goodhart’s law). I would rather say “I need to test the code” or “I need to test all those parts of the code”. See also what implies 80% of coverage in sonar?

Notes linking here