“I am ready to write some unit tests. What code coverage should I aim for?”
“Don’t worry about coverage, just write some good tests.”
“How many grains of rice should I put in that pot?”
“How can I possibly tell you? It depends on how many people you need to feed, how hungry they are, what other food you are serving, how much rice you have available, and so on.”
“Eighty percent and no less!” Replied the master in a stern voice, pounding his fist on the table.
“Great master, today I overheard you answer the same question about code coverage with three different answers. Why?”
“Come get some fresh tea with me and let’s talk about it.”
“The first programmer is new and just getting started with testing. Right now he has a lot of code and no tests. He has a long way to go; focusing on code coverage at this time would be depressing and quite useless. He’s better off just getting used to writing and running some tests. He can worry about coverage later.
The second programmer, on the other hand, is quite experienced both at programming and testing. When I replied by asking her how many grains of rice I should put in a pot, I helped her realize that the amount of testing necessary depends on a number of factors, and she knows those factors better than I do – it’s her code after all. There is no single, simple, answer, and she’s smart enough to handle the truth and work with that.”
“The third programmer wants only simple answers – even when there are no simple answers … and then does not follow them anyway.”