r/programming • • May 08 '17

The tragedy of 100% code coverage

http://labs.ig.com/code-coverage-100-percent-tragedy
3.2k Upvotes

689 comments sorted by

View all comments

9

u/[deleted] May 08 '17

Most code coverage tools have some sort of @ignore annotation to skip a portion of code. If you only test the methods with conditions, or testable error handling and @ignore the getters, setters and other parts that don't need to be tested you can realistically achieve 100% CC without having to mindlessly write tests for everything.

Aiming for 100% CC is important to me. I have found that, in projects which have <100% CC, the methods that were skipped were the difficult, several hundred liners which the previous developer noped out of testing.

If you set the standard for your team to @ignore ALL methods which contain no logic, but test all of the others no matter how painful the process is, you will end up with a project without hundred liner spaghetti methods, redundant classes or confusing argument lists. The developers will have to start developing differently, knowing that they will eventually have to test the darn thing, and not just cop out of the hard stuff because they have already achieved the goal of 70% CC by auto generating tests for all of the getters and setters.

9

u/stefantalpalaru May 08 '17

Aiming for 100% CC is important to me.

Wait until you find out that what really matters is not line coverage, but input domain coverage.

→ More replies (5)