Tuesday, 27 October 2009

Less Unit Testing Is Simply Bad Manners

The Agile Angel has come across a great many developers who hold strong opinions about testing. When to do it, how much to do, what should be tested, whether to mock or stub, ya-dee-ya-dee-ya. Even some of the most Agile fellows have tried to persuade her from time to time that perhaps they should do a little less unit testing.


Unfortunately most of these arguments are spurious and more often than not a plain waste of time.


The Angel would like to re-iterate some important facts about testing.


Fact: It is better to do too much than too little.


Instead of wasting your time debating about whether this or that unit test is worthwhile or if an acceptance test deserves automating, the Angel suggests you JFDI.


On numerous occasions she has heard a pair of developers argue about whether a unit test is truly necessary or not. In the time it took them to debate the point they could have just written the test. Stop wasting everyone’s time and code up the test. How far wrong can you go?


She suggests a thought experiment. Suppose for a given method you knew in advance the correct number of tests needed to provide optimal coverage. In this case you would not debate the point you would simply write the tests (you would do that wouldn’t you?). In the real world you cannot be sure where this optimal point is unless you are psychic. So, is it better to fall short or overshoot? What if the last optimal test is the one that detects the most serious defect? If you undershoot you run the risk of causing someone a problem.


And if you overshoot what happens? You spend a few extra minutes on testing but feel much better about your chances of not-being-a-twonk. A much better result.


Fact: You are not as good as you think you are.*


Too many developers overestimate their ability. In fact it is not just developers, human beings in general suffer from this problem. The Angel would like to remind all developers that humility is a powerful ally and the sign of a great professional. Assuming that you will make mistakes will lead you to conclude that better and more thorough testing are essential. She has only come across one team in nearly twenty years that held themselves down to a ‘virtually defect free’ output for any length of time.


Fact: Not testing is plain rude; defects are dirty.


The Angel can tell you with absolute certainty that the cost of a defect rises in a non-linear fashion the later in the process it is detected. There are sound, well understood economic reasons for testing early and often. But there is a much better reason for hiking up your unit tests. Good manners.


Passing on defects is rude. Its ignorant, selfish and unprofessional. The Angel is constantly irritated by the blindness of developers in understanding that if they themselves do not catch a defect then someone else has to. They are leaving a mess for someone else to clean up. You wouldn’t go to a friend’s dinner party and then stub out your cigarettes on the floor (she hopes), so don’t touch the codebase without ensuring you’ve tested your work. If in doubt, add more tests.


The Angel has, on occasion, performed the Product Owner role. This involves, amongst many things, reviewing and prioritising defects into her backlog. She can tell you that this is as onerous as picking up dog shit... from somebody else’s dog! She has to waste time prioritising, testers have to waste time filling in defect reports, Scrum Masters have to waste time discussing, chasing and scheduling and most importantly it is often someone other poor developer who has to clean up the mess as it can be difficult to trace a defect back to its originator. Its a pain, its costly and its a waste.


Don’t be rude.


Thorough unit testing is the software equivalent of having exceptionally good manners. She suggests we all behave like Gentlemen**.


* If you think you are, get a second opinion.

** or Ladies.

No comments:

Post a Comment