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:

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Ray Houston

Ray is a software development leader and architect with 20 years hands-on experience. He enjoys finding elegant solutions to complex problems and delivering real value to customers. Ray is a speaker and contributor to community events.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

7 Responses to Learning TDD

  1. Duncan Butler says:

    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.

  2. c says:

    - 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…

  3. Robb Schiefer says:

    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.

    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.

    Regardless, thanks for all your content.

  4. Ray Houston says:

    @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.

  5. Ray Houston says:

    @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.

  6. @Duncan Butler – I have the same question… =)

  7. anjalli says:

    i want to know institue which provide TDD training in Gujarat.
    n also the cost of training plz reply its urgent.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>