Top 12 Reasons to Write Unit Tests
Subject:   Testing is a wrong way ...
Date:   2003-04-29 05:57:18
From:   anonymous2
Response to: Testing is a wrong way ...

Yes, it's true that testing does not guarantee perfect code; yet it does provide a marginal benefit ("marginal" meaning that you spend a little bit of effort testing, and you get a little bit of benefit in return). And a marginal benefit is definitely worth something!

Unfortunately, the word "test" does suggest perfection to me... I wish for a better word, that conveys the idea of marginal benefit.

For some reason, when I write test code, it's very easy for me to fall into the trap of trying to make it perfect. Perhaps this is because of the problem of "false alarms" - that is, your test code has a bug in it, which makes it think your app code has a bug in it, when it doesn't really have a bug in it.

If you test code is imperfect in this particular way, it can really waste a lot of time.

BTW: While testing is obviously central to the XP canon, it doesn't seem to follow the same philophy, because of the need for perfection in this sense; and because you cannot write tests in an XP way (ie they have to work correctly and completely for them to be any use).

Regression bugs are pretty rare - the vast majority of bugs are new bugs whose cause you hadn't thought of before. In my experience, it is as miraculous as it is rare whenever an automated test actually catches a new bug.

For these reasons, they often aren't worth the effort for the marginal benefit they provide.
Of course, if you create a lot of regression bugs for some reason (eg interactions between components written by different people), then the marginal benefit is much greater.