DEV Community

Augusts Bautra
Augusts Bautra

Posted on

The Secret of Minimum Coverage

Today is the last day of work before holidays and I'm finishing up some chores.
One thing I wanted to do was to improve and increase the required minimum of spec coverage in our project. Get it from 30% to 35%. This is somewhat complexed by there being unspecced legacy code and us being unable to just set a blanket 90% minimum for all new files.

Going through the low offenders I came across a file like this:

The file has no specs, but it gets a surprisingly high coverage because of mere loading of the file. Every inclusion line will artifically pad coverage percent, ditto for various macro calls. No inclusions would still result in a 66% coverage.

This is bad news for our existing attempts to ensure good coverage for new code. Not sure what improvements we could make.
Maybe adding a linter that checks that every source code file has a corresponding spec file could be a simple improvement - reviewers are much more likely to spot an empty rather than altogehter missing spec file.
Another approach could be to subtract some rows (1-2) from total and covered counts, the example's 3/4 could become (3-2)/(4-2) = 1/2 = 50%.
Finally, dramatically increasing the minimum coverage to 76%+ would to the trick, but would require an inordinate amount of work to mark existing offenders with # :nocov:.

P.S. I ended up combining spec file presence check and high minimum coverage for all files except a special list of legacy offenders in a SimpleCov.at_exit block.

Top comments (0)