Saturday, March 05, 2005
Pragmatic Unit Testing in c# Review

Developer testing is a very interesting topic that gets more and more momentum everyday. All developers know they should be testing, but even with the advent of numerous tools to assist in testing, many still let it fall by the wayside.. As a developer, I've been using nunit for about a year now to test my professional code, as well as my personal code. That being said, I know I have not been using nunit as effectively as I could be, so a couple weeks ago I picked up Pragmatic Unit Testing in c# with nunit by Andrew Hunt and David Thomas hoping it would help get me thinking in TDD.

The book as a whole is relatively short, and an easy read. Direct and to the point, without being dry, I found it easy to just pickup and read this book cover to cover. There is also a good mix of commentary and code.

The first few chapters of the book act as an introduction to unit testing, and the basics of writing fixtures and tests with nunit. The authors do a good job of presenting the whys of unit testing, without being overly religious and theoretical, focusing on things like productivity and quality. The basics of nunit are then presented in a concise and thoroughal manner, showing enough code to feel like an nunit expert by the end of chapter 3.

The next three chapters focus on what to test, why, and how. These chapters were definitely the ones I took the most away from. The authors present a good set of concepts that will help developers think about their tests, and write the tests that will matter. Not too much code in these chapters, but since the chapters focused on the concepts of what to test, I didn't see that as a bad thing.

The last few chapters dive back into code showing how to apply the concepts from the first 6 chapters, covering mock objects, refactoring for testing, and TDD. These chapters take a higher level view at these concepts, showing some details here and there. These subjects could each fill a book themselves, and in fact do, but this book does a good job of providing an introduction to some of these concepts.

Overall, I enjoyed this book very much. It was a small, quick read, and pretty cheap, even at my local Borders. I would highly suggest this book for people that are looking to start unit testing, while those that have been writing tests for a while may want to peruse it first. I purchased this book hoping to think more TDD, but ended up just thinking about my tests more, which isn't a bad thing at all.