Wow – I was searching my email for something else and in passing re-discovered this except from an email I wrote in 2003. I still struggle with this in 2014. Here it is as is with small grammatical errors included:
“I did this last week with someone on my team at InfoHealth. This person had not unit tested the code (properly) and there were loads of errors. I fixed them by first writing the tests to catch the bugs and then methodically fixing them. I finally got to a green light. Yay.
A couple of days later this person changed something and whammo the website we were working on was giving the wrong results. This person was really having a rough time of it trying to find out what the problem was. I offered to setup the test harness on his machine but it didn’t eventuate (he had tried himself and was unsuccessful getting it to compile). The next two days he was away. I logged on to his machine and got the test harnesses to run and show the first error. I didn’t proceed to fix them though.
He then came back in. None of the bugs had been fixed yet after a day of some fruitless bug fixing previously. I told him to fix the bugs through the test harness. He ran the harness and discovered the first error and fixed it, and then the next and then the next. After about 90 minutes and fixing 9 or 10 bugs he was done. He comment afterwards was ‘Testing was never so much fun’
Hopefully I gained a convert to Test-Driven development. Only after demonstrating a regression test suite it made all the difference. This person was not on the project where we had previously done Test Driven development and I felt he was a somewhat cynical person as well who needed to be shown the light.
And so ends my anecdote.”
Testing is so important but we are still refining the practice. Lately James Coplien and David Heinemeier Hansson (DHH) have been wanting to scale back unit testing (both from different angles), removing some of the pedantic nature (my words). DHH wants to take it out a level to the integration. They both have valid arguments. See DHH’s article for more and this will have links to James Coplien’s ideas as well. On May 9 2014 Kent Beck, Martin Fowler and DHH will be discussing TDD in a google hangout entitled Is TDD Dead. It should be interesting and I’ll be tuning in.
Testing exists somewhere and we are trying to get to the sweet spot, balancing the risk mitigating advantages and the ROI on creating and maintaining them.
Edit: The second episode of the TDD occurred last Friday 16 May 2014. DHH struggled a little with his argument the TDD creates bad design. Perhaps more like inexperienced programmers create poor designs. James Shore weighs in here.
The HeartBleed bug and GOTO Fail bug in Apple products could have been prevented by a unit testing culture and saved a lot of time and money as a result. This article from Mike Bland explains. I’m of the same mindset that we should not resign ourselves to an acceptance of complexity and that these things ‘just happen’. Simple design and unit testing would have greatly mitigated these issues.
The non-unit testing culture means there are probably many other bugs waiting to be discovered. The relatively small impost on time to do unit testing and do it well is paid back many times over.
The twitter hashtag #IsTDDDead is covering the debate, although now seems to be simmering down.
Uncle Bob Martin puts TDD in the context of Teams, paraphrasing – Good personal hygiene is good for the team.