CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Darrell Norton's Blog [MVP]

Fill in description here...

Another TDD Sucess story

It’s so easy to work with Test Driven Development. For example, I recently had to go in and debug a data access method. Well, I was supposed to just add tests for it, but I ended up having to debug it. Hehe.

There were 3 DataTables, so instead of testing all three at once and trying to figure out the error I was getting, I commented out two and just returned the first one in the DataSet. Green!

Ok, then I enabled the call to the database for the second one. Red! So I looked at the stored proc and typed dataset, quickly figured out it was a mapping issue, and fixed the stored proc. Run NUnit again. Green! Finally I re-added the last DataTable code and ran NUnit. Green!

All done and no debugger was necessary (sorry John Robbins!). And this only took a couple of minutes. All it takes is for you to start using TDD where you can. Just start by writing some tests around some code that you work with every day. I guarantee it will help.



Comments

Steve said:

The debugger is evil! Whenever I start stepping through a peice of code in the debugger I know my tests aren't good enough. Anyway, great example of how TDD can be used on existing applications to help "debug" an application!
# May 27, 2004 5:43 AM

Darrell said:

Thanks to both of you!

Steve (Eichert) - good point about knowing your tests aren't good enough if you have to use the debugger.
# May 27, 2004 5:48 AM

Dave said:

As someone who is constantly trying to get more people into TDD, this is an example I'll be sure to use. Nicely done.
# May 27, 2004 6:08 AM

Darrell said:

Dave - thanks. The funny thing is, I was wondering whether this was even blogworthy or not.
# May 27, 2004 7:01 AM

Paul Bartlett said:

I don't think there's any need to apologise to John Robbins. IIRC, he more than most thinks developers spend to much time "in" the debugger when solving problems.
# May 27, 2004 9:24 PM

Darrell said:

Paul - yeah, I was just joking. Some WeProgram.NET user group members (my user group) talked with him about debugging. But if TDD reduces the need for debugging, he won't sell as many books. :)
# May 28, 2004 1:35 AM

A'braham Barakhyahu said:

How would you TDD a DAL which calls a stored procedure that has joins? I'm doing one part of a bigger project, where writing procedures to created and delete the tables involved would take a bunch of time. I can pull the expected data manually, store in a datarow and compare to the one i pull, but that's doesn't seem like the best solution. Any suggestions?
# December 3, 2004 4:03 AM

Darrell said:

A'braham - that's actually what I do for a couple of reasons.
1. It's fast.
2. It is probably the best check to see if what you are doing is what you intended to do.
3. It's clear and easy to understand.

I'm sure there are other ways, maybe even better ways, to do it, but for now that's what I do.
# December 3, 2004 4:56 AM
Check out Devlicio.us!