Tuesday, September 1, 2009

TDD

Test driven development is a good thing. It can be hard to implement in practice due to deadlines and it not being readily accepted that tests absolutely have to be written.

Case in point. A class was written (as a collaboration of two). The class functioned satisfactorily. With a look of horror, some unit tests were created for this class by a concerned outsider. With some trepidation, the collaborators added more unit tests and eventually every function was covered by the class (thanks to EclEmma) - not every line, but at least every function had a little coverage.

With the dawning of a need to extend the class (4 months on) a new journey dawned. The first challenge... get to 100% coverage. Once that was achieved add the new unit tests, then the code. Horror. The added tests failed. Bugs everywhere. An absolute infestation.

The bugs were not in the code that was used. The code that was used, was adequately covered by the unit tests. The problem was the interface. The exceptions and, obviously, never used paths.

I headed for 100% coverage as I had achieved it in creating another class and had a feeling of confidence in the class overall and not just the paths I knew I was using.

Even when no problems have been found, there are worthwhile solutions.

No comments: