
Early in the morning, the programmer asked the great master:
- I am ready to write unit tests. What code cover should I aim for?
The great master replied:
- Do not worry about coverage, just write good tests.
The programmer smiled, bowed and left.
A little time later, another programmer asked the same question. The great master pointed to a cauldron of boiling water and said:
- How many grains of rice should I put in this pot?
The programmer with a puzzled look answered:
- How can I answer for sure? It all depends on how many people you need to feed, how hungry they are, what other dishes you serve, how much rice you have, and much more.
- Absolutely. - said the great master.
The second programmer smiled, bowed and left.
At the end of the day, the third programmer came, and asked the same question about code coverage:
- Eighty percent and not a line less! - Master replied sternly with his fist on the table.
The third programmer smiled, bowed, and left.
After this answer, a young student approached the great master:
- Great master, today I overheard how you gave three different answers to the same question about code coverage. Why?
The great master rose from his chair:
- Come with me, take freshly brewed tea and talk about it.
')
After they filled their cups with hot green tea, the great master began to answer:
- The first programmer is a beginner and is just starting to write tests, now he has a lot of code and no tests. There is a long way ahead of him, and concentration on the coating is now useless and will only depress. Let them get used to writing and running tests better. He may worry about coverage later.
- The second programmer, on the contrary, is quite experienced in programming and testing. When I asked her how many rice grains I needed to put in the pot, I helped her realize that the number of tests necessarily depends on many factors, and she knows these factors better than me - this is her code after all. There is no one simple answer, and she is smart enough to accept the truth and work with it.
“It is clear,” said the young student, “but if there is not one simple answer, then why did you answer the third programmer with Eighty Percent and Not a Less Than Line?”
The great master laughed so loudly and loudly that his belly, the proof that he drank not only green tea, jumped up and down:
- The third programmer wants only simple solutions, even when they are not there. And after, it still does not follow them.
The young student and the great gray-haired master drank their tea in thoughtful silence ...