“我明白了，” 年轻的实习生说， “但是如果没有一个简单直接的答案，那你为什么告诉第三个程序员‘百分之八十，不能少’呢？”
“这第三个程序员只想得到一个简单的答案——即使根本没有简单的答案 … 而且即使有答案她也不会按答案做。”
by Alberto Savoia
I first posted this article a few years ago on the Artima Developer website; but the question of what's adequate code coverage keeps coming up, so I thought it was time for a repost ofTestivus wisdom on the subject.
Testivus on Test Coverage
Early one morning, a young programmer asked the great master:
“I am ready to write some unit tests. What code coverage should I aim for?”The great master replied:
“Don’t worry about coverage, just write some good tests.”The young programmer smiled, bowed, and left.
Later that day, a second programmer asked the same question.The great master pointed at a pot of boiling water and said:
“How many grains of rice should I put in that pot?”The programmer, looking puzzled, replied:
“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.”“Exactly,” said the great master.The second programmer smiled, bowed, and left.
Toward the end of the day, a third programmer came and asked the same question about code coverage.
“Eighty percent and no less!” Replied the master in a stern voice, pounding his fist on the table.The third programmer smiled, bowed, and left.
After this last reply, a young apprentice approached the great master:
“Great master, today I overheard you answer the same question about code coverage with three different answers. Why?”The great master stood up from his chair:
“Come get some fresh tea with me and let’s talk about it.”After they filled their cups with smoking hot green tea, the great master began:
“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.“I see,” said the young apprentice, “but if there is no single simple answer, then why did you tell the third programmer ‘Eighty percent and no less’?”The great master laughed so hard and loud that his belly, evidence that he drank more than just green tea, flopped up and down.
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.”The young apprentice and the grizzled great master finished drinking their tea in contemplative silence.
I think our industry would benefit to have more of the first two people and a whole lot less of the third.Reply
Is this about developers or testers? The story is nice though. But again it looks like the testing is only scripting in your place.Reply
I would say to the experienced dev: Reply
"Aim for an increasing trend in code coverage"
The Way of Testivus is the best thing I've seen in a long time. Well done.Reply
The story is definitely not just about code coverage :)Reply
We need great master...........Reply
Just give the consultant answer, "It depends..." :)Reply
Hope that I have a great master who can drink some tea with me. ;)Reply
We need more great masters Reply
very cool. Thanks for sharing!Reply
I would like to translate your post to portuguese and post it on our website, because I have a few coleagues that aren't comfortable reading in english and would benefit from your post. Can I do it?
I really like the managers attitude. I wish people would customize to help people with various skills and experience insead of assuming that one set of instructions will get us similar results. This note is really about master understanding his people.Reply
I guess it is a nice way to let people understand about the code coverage. Or any other question.
I guess this is about the attibute of a person how we react in our day to day job.
Regarding the Code Coverage. I guess the first answer was quite important. Just try to concentrate on writing the good test, instead of worring about the coverage. It is important to dissuss those test with bussiness, through that a person should be able to figure out the coverage achieved in the test.
But nice and cool approach. :)
Really nice story! Perfect introduction to code coverage for developers and project managers in particular!Reply
>I would like to translate your post to portuguese and post it on our website ... Can I do it?<Reply
Hi Julio, no problem. I'd love to see Testivus in Portuguese or any other language. Thanks, Alberto
This comment has been removed by the author.Reply
Look into T.D.D., XUnit, and other pre-cog code coverage methodologies that inherently strive for 100% coverage.Reply
This story has earned me huge amount of repu points on StackOverflow: http://stackoverflow.com/questions/90002/what-is-a-reasonable-code-coverage-for-unit-tests-and-why/90021#90021Reply
It remains to be one of the most excellent answers to the code coverage issue.
Great story! Love it! Reply
Published a german translation here: http://itscertainlyuncertain.blogspot.de/2013/01/testivus-zum-thema-test-coverage.html