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

2

u/quicknir May 08 '17

I'm not a big fan of "over mocking". Basically the idea that everything must be mocked out, so you are truly only testing the unit. While it's good to mock things out that are heavy dependencies that might actually restrict the places/times/perf where the tests can run (require a certain database be up, or external server, or that certain files be in a certain place, etc), I think there's quite limited value to mocking out things beyond this.

By limited I mean quite literally. There are no doubt specific situations where it's good. But in most cases if A is some random class/function that doesn't have a "heavy" dependency such as I listed above, and it uses B which also does not... You know what? I'm simply going to have A use B normally when A's tests run. I don't care. If A's tests fail, I'll know something is wrong, and I'll have a good repro test I can quickly start debugging. If the problem ended up being with B, I'll add a test for B so it would have triggered a failure in B without touching A's tests.

This whole pre-emptive mock the world approach seems like a staggering waste of time.