Jef Claes

On software and life

06 Oct 2011

Book review: The Art of Unit Testing

I think The Art of Unit Testing targets a broad audience. Beginners will find every part of the book useful, where intermediates might be more interested in the final two parts.

Roy Osherove starts this book by laying a solid foundation of the unit testing concept. Why is testing important? What defines a good unit test, and how does a unit test differ from an integration test? In the second part of the book, he demonstrates the use of two core unit testing techniques: stubs and mocks. After showing you how these techniques work, he shows off various isolation frameworks which can help you creating stubs and mocks at runtime (fakes), greatly reducing the effort of writing these objects.

If you have some experience with unit testing, you might not be impressed with the content of the book so far. If you’re somewhat like me, and have been writing tests for some while, but often find yourself wondering if your tests will still be considered solid six months from now, you will find the content of part three very useful. In this part, Roy talks about organizing your tests and how to strive for satisfying the three pillars of good tests: trustworthiness, maintainability and readability.

The final part wasn’t something I expected to find in this book. In this chapter it’s very clear that the author has been an agent of change himself for a long time. Next to sharing successful strategies on how to usher testing into the organization, he answers a bunch of hard questions you will be asked when you’re on your own quest to bring change.

As I said before, there’s something in the book for everyone. While there are a lot of topics discussed, the book counts less than 300 pages. It’s well written at large, sometimes a bit sloppy, but in general a smooth read. All of the concepts are explained using examples written in C#, where the problems are small enough to keep it simple, yet comprehensive enough to make it a plausible scenario.

If you want to start out with unit testing, are looking for confirmation on how you’re doing or want to refine some techniques, this book might be the one to get.