The cost of unit tests
Unit testing is a recurring theme for me these last weeks; between talking about Stackoverflow and other forums and the tests that I write for two ongoing projects, I asked a few questions about the actual cost of the unit tests.
This is especially an article by Thomas Brandt (German: “TDD in der (my) Practice - wish and reality”) that made me think seriously. Brandt describes in his article quite well indeed this gulf between theory and practice of Test Driven Development. Point blank, Rather, it adheres to the principles of TDD;
I must first say that Test Driven Development, especially the principle of "first test", is a rather “sexy” develop. It can certainly improve the software architecture and prevents us from doing certain (small) errors.
— Relatively free translation of about T. Brandt
He therefore considers TDD as a powerful tool – at least from a purely academic. But the immediate result is a doubt;
The question is simply: at what price?
As mentioned, except T. Brandt and I, many other people seem to ask, and the most frequently asked question is as follows: Is that the use of unit tests does she really better software, and is that efforts to invest are they realistic?
Condensed, the question boils down to a simple:
It cost me how much the unit tests?
Often the question involves, that he who raises think unit tests are too expensive to apply consistently. I remember a discussion I had about the value of a total test coverage beyond the theoretical ideal. Reported efforts to provide I said “not” at the time.
As of today I think all these questions are asked simply evil, because it is not know the cost of unit testing is important, more:
How do I pay the omission of unit tests?
And here is my answer, illustrated using a concrete example;
One of my current projects include a large number of distributed components. I discovered an error in the draft, which forced me to refactor both classes. All took me about 1 hour. Launch unit tests? About 30 second. 30 seconds, I discovered that some behaviors were not as originally planned. It took me about 20 minutes for corrections. Writing tests cost me about 45min.
The balance sheet is about two hours.
Without unit tests, I probably would not notice some of the errors immediately. I would have had 1 time refactoring, over a more or less determinable, certainly spread over several days, to correct the problems go unnoticed when changing. The probability that this time goes well beyond an hour is relatively high (debug “hand”, recreate conditions in multi-threaded apps etc.…).
For my part, I find that to calculate a defined time (having tests covering a realistic part of the software – not 100%) more interesting is that navigation in the dark as practiced.
Experiment!



