Recently there was a blog posting and a rebuttal and I found that I agreed and disagreed with both. I’d like to briefly discuss them and my opinions on them.
The Party of the First Part
Naresh Jain posted about his opinion about TDD and his ‘dilemma’. He discusses what he sees as the costs of unit testing, both the obvious (writing, running, maintaining), and ones he lists as ‘subtle’.
These subtle ones I recognize but perhaps do not entirely agree with: illusion of safety, opportunity cost, getting in the way, obscuring simpler design.
He concludes with:
Its easy to say always write unit tests, but it takes years of first-hand experience to judge where to draw the line.
I do not find this unreasonable.
The Party of the Second Part
In response Robert Martin posted his riposte. It is a piece of parody and while amusing I think is a smidge off the mark. He again draws the analogy between unit testing and double-entry bookkeeping. He uses the same obvious and subtle costs for double-entry bookkeeping (my understanding of double-entry bookkeeping is limited but his parody seems accurate).
It is obvious that Martin does not believe Jain’s conclusion is reasonable.
To me Jain’s post is mostly reasonable. I have a minor disagreement with his obvious cost of ‘…understanding other’s unit tests’. To me this is NOT a problem of unit testing at all but of ANY code. Concerning his subtle costs I can agree with this first, understand his second but disagree with his third and fourth. Unit tests are a safety net. But this do not make you safe from all danger. You need to know what they cover and what they don’t. There are opportunity costs, I would not unit test a spike and a several spikes, each of which I throw away, may definitely be a better use of time then a single attempt at unit testing a solution from scratch. However I will then unit test the final solution. His third and fourth points are again not a problem of TDD but a problem of all code.
Martin’s riposte is amusing and I can imagine him speaking it in his particular style. However I ultimately feel it is a flippant response. I don’t think Jain’s position is worthy of ridicule. I think it is worthy of disagreement.
I am not suggesting some sort of PC-ish self-censoring or to ‘Teach the Controversy’. I disagree with Jain’s post. I have found (warning anecdote:) that TDD outweighs the costs 95% of the time, and in fact the remaining 5% is shrinking as I continue to learn.