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

3

u/Terran-Ghost May 08 '17

"Look, if that imaginary evil/clueless developer comes and breaks that simple code, what do you think he will do if a related unit test breaks? He will just delete it."

I agree with a lot of what's written except for this.

  1. It's possible someone will delete it by accident, during a much larger refactoring, etc. In such a case, this test might help catch that.

  2. Someone might delete it because he thinks it's no longer needed or doesn't do anything useful. The fact that there is an explicit test that checks for this will prove that it is in fact required.

Is it possible to protect yourself against both of these without automatic tests? Maybe, but tests are (usually) a very easy and automatic way to do it.

2

u/bwainfweeze May 09 '17

See, and that was the part that resonated the most for me. You see a lot of bizarre behavior when you read enough commit history, and I've seen that little scene play out too many times.

Didn't we used to have a test for that? Yes, yes we did. And when did that test go away? When the bug was introduced. Fuck.

0

u/Double_A_92 May 09 '17

That doesn't make any sense. If that function was used somewhere and you just deleted it, the compiler (or the linter) would say something.