One day, early in the morning, a young programmer turned to the great master: β
I am ready to write several unit tests. What code cover should I aim for? ".
The great master replied: "
Do not worry about the coating, just write good tests ."
The young programmer smiled, bowed and left.
')
On the same day, the second programmer asked the same question.
The great master pointed to a pot of boiling water and asked: β
How many rice grains should I throw in the pot? ".
The programmer, perplexed, said: β
How can I answer? It depends on how many people need to be fed, how hungry they are, what kind of food there will be, how much rice there is, and so on . β
β
Exactly! β- said the great master.
The second programmer smiled, bowed and left.
By the end of the day, the third programmer came and asked the same question about code coverage.
β
Eighty percent and no less! ", - replied the master sternly, banging his fist on the table.
The third programmer smiled, bowed and left.
After this answer, the young student addressed the great master: β
Great master, today you gave three different answers to the same question about code coverage. Why? ".
The great master rose from his chair: "
Let's drink some tea and talk about it ."
After they filled their cups with steaming hot green tea, the great master began:
β
The first programmer is a beginner, he just recently engaged in testing. Now he has a lot of code and no tests. He still has a lot to do; it will be difficult and useless for him to concentrate on covering the code now. He is better just to get used to writing and running some tests. He may start worrying about coverage later.The second programmer is quite experienced in both programming and testing. When I asked how many rice grains I had to put in the pot, I helped him to understand that the amount of testing needed depends on a number of factors, and he knows these factors better than I do - this is his code. There is no single simple answer, and he is smart enough to figure it out . β
β
I understood ,β answered the young student, β
but if there is no single simple answer, then why did you answer the third programmerβ Eighty percent and no less! β β?
The great master laughed: "The
third programmer needs only simple answers - even if there are no simple ones ... but then he shouldn't follow them anyway ."
The young apprentice and the great gray-haired master finished drinking tea in thoughtful silence.