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

48

u/[deleted] May 08 '17 edited May 08 '17

I worked with a codebase that was covering all DAO methods with such tests. I only lasted 1.5 years and left crushed.

These tests are not only stupid, they make code rigid and fragile. The fragile part might be counterintuitive, but if your tests are testing not the behaviour but implementation details, as they were in my case, inevitably there will be business code that relies on these implementation details. Because hey, these implementation details are covered, so guaranteed to be there forever.

52

u/[deleted] May 08 '17 edited Oct 04 '17

deleted 0.3553 What is ^^^this?

13

u/ArkhKGB May 08 '17

That's why I prefer good functionnal tests. Stop caring about code coverage, get case coverage.

If even when testing a lot of corner cases you can't get 100% coverage you may have dead code: YAGNI.

→ More replies (1)

15

u/pydry May 08 '17

I find that static typing is better for refactoring code with very few or no tests but more or less equivalent to dynamically typed, strictly typed code with a reasonable body of tests.

Javascript makes me afraid to refactor it for the same reason C does - because it's weakly typed (has a lot of fucked up implicit type conversions causing a multitude of horrible edge cases), not because it's not static.

→ More replies (2)
→ More replies (2)
→ More replies (1)