Saturday, January 26, 2013

There's a Bug in My Test!

Since becoming sold on TDD a while ago, I've noticed something bothersome. It's hard to write correct automated unit tests!

Unit test code is just as likely as any other program to contain bugs, logic errors, and defects. Code that passes the tests then is still likely to have bugs. Damn, all that work for nothing!

Not quite. There are plenty of benefits of writing unit tests prior to coding the actual deliverable product.

Writing unit tests first forces me to write the product code in a more testable, more modular style. This happens to be a more maintainable style also. So, it's easier to find and fix the inevitable bugs when they raise their dirty little heads.

Designing the unit tests makes me think about the program more deeply, also. I give more thought to the use cases, range of possible inputs, the required outputs, and possible exceptions. In short it makes me more thorough.

So I'm sticking with TDD.