Test-driven development (TDD) is a programming technique heavily emphasized in Extreme Programming. Essentially the technique involves writing your tests first then implementing the code to make them pass. The goal of TDD is to achieve rapid feedback and implements the "illustrate the main line" approach to constructing a program.
That is the definition that appears in Wikipedia. I have stuided Extreme programming quite a bit but writing tests before hand has never been something that seemed that exciting to me. I am in the middle of a project and I decided I needed to write some unit tests to augment the build process so I have some confidence the code is working well as I continue to work on it. So I decided to use DUnit which is a testing harness for Delphi XP. I've used it before with good success and I've managed to integrate DUnit console tests with FinalBuilder. I like doing a build and knowing that my tests are passing.
Well I managed to write some tests the other day that didn't pass, much to my surprise. So here I am writing all sorts of mundane tests and I'm finding out I actually like doing it, much to my surprise! For one thing, I found a few bugs that I may not have found for quite awhile. Not to mention that finding them would have been done after some weird bug was found. Finding a bug may take one minute or it may take one week. I wasn't looking to find bugs. I was looking to write tests and when I found out they didn't pass, well I was testing at a fine enough level that it took very little time to find the source of the problem. That's what I like about this technique. You are testing something at a low enough level that if it doesn't pass, you'll find the bug right away. In many respects, this is so much easier than doing it the old way and it's proactive. You aren't waiting for a bug to bite, you're getting rid of the rascals before they can do their damage.
Well I'm sure I'll be learning a lot more but I wanted to get that much documented.
So I'm more sold on this idea of writing tests before you get very far.
Comments