“But what if you write a bug – like a typo or something – into the test? I mean, your tests aren’t going to be perfect, are they?”
This is a genuine question someone – understandably – asked me earlier this week when I was introducing them to the idea of TDD.
I have two answers to this question: The math answer and the Starwars answer.
1) The math answer:
[note]If P(Error) is the probability of any line of code you write containing an error, and you write t lines of test code and tn lines of production code, where n is greater than 1, then bugs in both tests and production code can only slip through when they coincide, and you will fix tn bugs in production code for every t bugs in the tests.