That’s perhaps the most surprising, powerful and reassuring sentence I’ve read on stackoverflow since I write code ! Kent Beck, respected authority, creator of Extreme Programming, TDD and writter of several great reference books, mainly at the great Addison-Wesley edition, have answered the following text to someone asking “how deep do you unit test”. Myself I usually break on this question as I tend to be JEST (Just Enough System Testing) in the JESA spirit (Just Enough System Analysis, great book) from Jesa Yourden. And as I’ve started to go deep in BDD, the question was even more important as I can really quickly test stuffs but also forget to test specific dark cases that I would probably test in a more classical TDD way. So here’s the inspiring Beck’s answer :
I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don’t typically make a kind of mistake (like setting the wrong variables in a constructor), I don’t test for it. I do tend to make sense of test errors, so I’m extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong.
Different people will have different testing strategies based on this philosophy, but that seems reasonable to me given the immature state of understanding of how tests can best fit into the inner loop of coding. Ten or twenty years from now we’ll likely have a more universal theory of which tests to write, which tests not to write, and how to tell the difference. In the meantime, experimentation seems in order.
So when that kind of ground breaking answers are made by that kind of guy… it’s always good to meditate a bit on it !
Indeed, since this answer, 5years ago, some big improvements have been made, but it’s still a great view from a inspiring person.
The original StackOverflow topic : http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565
Catch you next time and keep it bug free !