in

blog.dashpoint.com

Blog home for Rod Paddock and Dash Point Software, Inc.

Rod Paddock

My First TDD Dividend(s)

It’s now 6:30am here in Austin, TX and my first forays into TDD have paid their first real dividends.

Roy Osherove (http://weblogs.asp.net/rosherove/) and I spent a couple of hours yesterday going over my system framework/architecture, installing nUnit and Test Driven.NET. We wrote one very simple contrived test and then left for BBQ with our bud Scott Bellware.

So it’s 4:00 am and I cannot sleep so I get up, do some client work and then return to so some tests on my own.  So I refactored my customer business object. I added a rule to check that the last name is filled in.  Then I wrote another test. The goal of this test was to make sure my validation engine worked and returned the proper error conditions.

So I ran the test and it failed. I’m like what? This should have worked. Why didn’t my rule(s) fire? So I looked into the framework code and low and behold. Looks like I never finished wiring in our new validation rules engine. 

BINGO: Dividend 1 paid. We now need to finish wiring in the new validation engine.

So now I returned to making the test pass. I had a hook point where I could wire in manual calls to the validation engine. So I did that and restarted the test.  Boom another failure. Now what happened? We have a set of code the integrity of the data being returned. Well when we have a data validation error we don’t return that data.  Nice thing is that this section of the application is created via code-gen. I simply changed the script to test for the error condition. Now our test passed.

BINGO: Dividend 2 paid. We needed to fix some of our codegen templates.

So with just a few simple tests I found two very significant bugs in our framework. It’s nice to see that this stuff pays off so quickly.

The nice thing is that now I am confident that this stuff pays great dividends (and very quickly I might add). Also it’s great to see that it CAN be implemented against our framework.  

 

Comments

 

Kevin Miller said:

Congrats on your dividends! May they multiply.

Strangely when I am doing TDD I love the little adrenaline surge I get when a test that I expect to pass fails. But I love even more constant endorphin drip I get doing red-green-refactor.

October 5, 2007 6:48 AM
 

cmyers said:

Once you get test infected, then the other things, like DI/IoC for example, start making more sense. Admittedly, they're not super useful unless you're religious about testing which is why I think a lot of people don't understand/get irritated by the TDD/Agile/ALT.NET crowd because all these things seem like extra work.

It all starts with TDD, really, and then you start writing code differently in order to make them easier to test.

IMHO, code written to be tested is also code written to be used. It tends to be more open and extensible and easier to change/override/extend.

Some of the best framework/API-type code I've ever written was code that was developed using TDD.  It pays off in more than just bug prevention, it pays off in the resultant good, quality design.

Not to mention that TDD code is code that has actually been used by at least one person!  Before TDD, much of the code I wrote was YAGNI stuff that didn't get hit for months or years and then suddenly a bunch of bugs were found!

October 5, 2007 9:36 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
Powered by Community Server (Commercial Edition), by Telligent Systems