By Peter Bell

Books on Unit Testing and Test Driven Development

I've read a number of books either about Unit Testing and TDD or that include information about them. Here are the resources I've found most helpful. Any other recommendations appreciated . . .

The best two books for getting started with TDD are Kent Beck's original "Test Driven Development: By Example" and David Astlers "Test-Driven Development: A Practical Guide".

To get the philosophy of TDD, Becks book is ideal. He runs through a simple "money" example based on some work that he did with Ward Cunningham and then goes on to show how he wrote the Unit Tests for JUnit (including showing how you really can solve bootstrap problems such as writing unit tests for a unit test framework!) which gives a much better sense of how he was thinking about the process.

David Astlers book provides another perspective and lots of specific examples of writing an application using TDD and is a great compliment to Becks book if you read it but still aren't quite sure where to go next.

Recently I've also heard good things about Lasse Koskela's Test Driven: TDD and Acceptance TDD for Java Developers, although I haven't read it yet (anyone had a look at this one?).

There are also chapters in books like Head First Software Development, Practices of an Agile Developer and Ship it! which are well worth reading. As with most things, reading a wide variety of source materials gives you a much richer feeling for a solution space, so I'd thoroughly recommend reading a few books to start to get comfortable with Unit Testing and TDD.

In terms of Unit Testing, I'm also just working my way through Pragmatic Unit Testing in Java with JUnit which provides lots of great additional information on naming and structuring tests, how to use mocks, and patterns and anti-patterns to consider. I'd definitely recommend it as a good practical "first book" for Unit Testing although I think that Becks book is still essential if you want to really get the feeling for what TDD (as opposed to just writing Unit Tests) is all about.

Any other recommendations for books on TDD or Unit Testing?

Comments
I'd recommend trying it out too. Reading won't give you a feel for it all. =)

I know you weren't suggesting reading to the exclusion of acting, but I think the hardest step in all of this is to actually *do it*, because you'll never get over that initial fear of "I don't know how to do this, what if I fail" until you do.
# Posted By Sammy Larbi | 4/16/08 11:18 AM
Agreed. There's a lot to be said for "just do it". That said, I'm a big fan of learning as much as possible from other peoples mistakes (having learnt way too much the hard way in the past), so I'd recommend the books as well if you have the time!
# Posted By Peter Bell | 4/16/08 11:52 AM
I've read "most" of the "Test Driven" book. It's quite good. For me, following him along as he really works through the red-green-refactor approach on a Template Parsing engine (engine may be too strong a word, but still) really crystallizes the concept. I think he does a great job of emphasizing the "refactor" part of the process. it's not just "get to green then you're done".

I think after reading that book I came away with a new appreciation for how TDD drives your design, and I can see in my own coding how that is happening.
# Posted By marc esher | 4/16/08 12:06 PM
To be clear, I'm not saying "just do it" to the exclusion of the books either.

"My advice is to do it by the book, get good at the practices, then do as you will. Many people want to skip to step three. How do they know?"

That is true - you should learn from the book as well. Just don't stick to doing only reading - give it a whirl as you read, would be my advice (again, you is not referring specifically to "Peter Bell" here, it's just general)
# Posted By Sammy Larbi | 4/16/08 12:25 PM
@Marc/Sam, great comments guys - thanks. One of the things I really love about this blog is the wealth of experience that the various commentors bring to the subject to round out the learning experience rather than it just being "one guy talking"!
# Posted By Peter Bell | 4/16/08 12:41 PM
Guess I should have looked through all your posts today Peter! I'll double post my comment for others that may not be reading all the posts. "Working Effectively with Legacy Code" is a great book, not necessarily focused on TDD but Testing is a pivotal concept stressed in the book.

http://www.amazon.com/Working-Effectively-Legacy-R...
# Posted By Adam Haskell | 4/16/08 10:35 PM
@Adam, Agreed! Michael Feathers is a fascinating guy. He gave one of the keynotes at the SPA conference and I ended up chatting briefly with him at Kings Cross before we went our separate ways.
# Posted By Peter Bell | 4/17/08 12:20 AM
I just finished reading Beck's book and "Pragmatic Unit Testing in C# with NUnit", which is the .NET equivalent of the JUnit book you mentioned. I thought they were a pretty good combination: Beck's book is a good introduction to the TDD methodology, and the Pragmatic book provides a good introduction to some real-world tools for putting that methodology to work.

I'm looking for a good third book that will provide some more advanced examples... I might give Astlers' book a try.

@Sammy: I agree with "just do it". The sooner you make the newbie mistakes the sooner you learn from them and stop being a newbie :)
# Posted By Seth Petry-Johnson | 4/29/08 12:51 PM
Astels is pretty good, and Marc Esher likes Lasse Koskela's book (I've not read it yet). More than anything I would *thoroughly* recommend Dan Norths article on TDD:
http://dannorth.net/introducing-bdd

I also found the following IM to be really valuable:
http://www.pbell.com/index.cfm/2008/4/17/I-Just-Go...

Also, Dave Astels recently wrote something on BDD as he's now involved with the Ruby rspec implementation (can't immediately find the link).

If you're interested in testing, I'd thoroughly recommend checking out the ideas behind BDD as it's often described by experienced TDD'ers as "TDD done right (i.e. good TDD'ers already do things this way).
# Posted By Peter Bell | 4/29/08 1:56 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.