Los Techies : Blogs about software and anything tech!

Learning TDD


Learning TDD takes time and can be especially tough if you don't have an opportunity to work with folks that are already doing TDD. It requires you to think and work differently and there are many pitfalls along the way. I know that I've made a ton of mistakes.

When I started working with automated testing, I was writing tests that hit the database. They were big, slow and complex and required a lot of maintenance to keep the data population scripts in check. The tests were very fragile and it seemed like it was almost a full time job to keep them going. At the time, I thought that doing TDD was just about writing your tests first so I tried doing it, but it was just too hard because I wasn't writing my code in a manner that could be tested easily.

Next I learned about dependency injection and IoC containers which allowed me to decouple my classes and test them in isolation. I learned how to create a mock instance of an interface and pass it into the classes that I was testing to see if they interacted with it properly. This was a million times better than the tests that ran against the database, but I still wasn't doing it right. I wrote all my tests as interaction tests (versus state base tests) and I ended up with a big mess of fragile unreadable tests that gave me very little feed back to the source of problems when they occurred. Refactoring was painful because I'd have to go fix a ton of tests that I could no longer understand what they were trying to test in the first place.

There are a lot of other mistakes that I'm forgetting right now (or just too embarrassed to mention) and I'm sure there are tons of other people who have made the same ones. As Jimmy pointed out, hiring a good coach can be well worth it in avoiding some of the mistakes like I made.

If you're interested in talking with other folks about TDD, Los Techies is hosting a free event in Austin, TX called "Pablo's Days of TDD" (PDoTDD). It will be held on Friday October 3rd, 2008 from 2PM-5PM and Saturday, October 4th, 2008 from 9AM to 5PM. This event is for all levels from beginners to masters and will include workshops, discussion, practice, and training around automated unit testing, specifically the practice of TDD. For more information, please see Chad's post here.

Technorati Tags:
Kick It on DotNetKicks.com
Posted Sep 23 2008, 09:22 PM by Ray Houston

Comments

Duncan Butler wrote re: Learning TDD
on 09-24-2008 4:10 AM

why oh why are these events always in "Another Country"!!

please please video this an make it available us all, finding "good" TDD meterial is very diffecult, and finding help in any form is great.

Dew Drop - September 24, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - September 24, 2008 | Alvin Ashcraft's Morning Dew
on 09-24-2008 8:08 AM

Pingback from  Dew Drop - September 24, 2008 | Alvin Ashcraft's Morning Dew

c wrote re: Learning TDD
on 09-24-2008 11:44 AM

- do you not write any tests for the database integration at all now or you separate them to run independently from he purely state based?  

I'm still trying to get the hang of tdd and am definately not working in a TDD shop...

Robb Schiefer wrote re: Learning TDD
on 09-24-2008 11:49 AM

I would love to come too, but work and family aren't flexible enough for me to take a road trip from Birmingham, AL.  Granted I'm in the same country (sorry Duncan), but I might as well be across the world.

I really enjoy your blog and know the event would be hugely helpful to me as well.  If you have decided not to video the event yourself, how about Ustream.tv?  They will broadcast your event live and I believe archive it to watch later.  All for free.  

Most new laptops come with webcams and mics in them.  All you would have to do is setup one of these laptops in each of the presentation rooms.  

<GuiltTrip>Your blog has become an international information souce for developers.  We can't all live in the greater Austin area.  You owe it to your readers to make this attempt.</GuildTrip>

Regardless, thanks for all your content.

Ray Houston wrote re: Learning TDD
on 09-24-2008 12:25 PM

@c - We have other types of tests that verify the application from end to end (integration tests) which do hit the database, but for our unit tests, they do not hit the DB.

When I mentioned state based testing, what that means is that I'm verifying that the properties of my object under test are what they're expected to be after a specified operation. Interaction based testing means that I'm verifying that my object under test is calling methods and properties on its dependencies correctly. The interaction based testing makes it tough when I want to refactor the way I implemented something without changing its functionality.

Ray Houston wrote re: Learning TDD
on 09-24-2008 12:37 PM

@Robb - thanks for the kind praise. When you say "your blog" I'm sure you mean the whole LosTechies blog and not just mine. Either that or you have me confused with somebody else. ;)

@Duncan & @Robb - I know that several of us are going to attempt to record "something". I can't make any promises to what we'll get and the quality, but we're going to make an effort. I'll have to check out Ustream.tv too.

Arjan`s World » LINKBLOG for September 24, 2008 wrote Arjan`s World &raquo; LINKBLOG for September 24, 2008
on 09-24-2008 3:18 PM

Pingback from  Arjan`s World    &raquo; LINKBLOG for September 24, 2008

Alexander Byndyu wrote re: Learning TDD
on 10-16-2008 12:53 AM

@Duncan Butler - I have the same question... =)

anjalli wrote re: Learning TDD
on 06-08-2009 7:13 AM

i want to know institue which provide TDD training in Gujarat.

n also the cost of training plz reply its urgent.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems