XUnit Test Patterns

XUnit Test Patterns

If you want to know everything there is to know about xUnit Testing, then xUnit Test Patterns by Gerard Meszaros is the book for you. I must warn you, it is not light reading (it’s almost 900 pages) and it is not geared towards beginners. You should at least be familiar with the concept of unit testing before trying to conquer this book. Reading it feels like completing a graduate course in computer science.

The Good

The book has some really great content. It covers a wide range of topics including testing strategy and principles, the details of exactly how xUnit works; test smells, refactoring and maintenance; test code organization and reuse; various fixturing strategies; design for test including humble objects, dependency injection and test doubles; and strategies for testing databases.

The thing I really like about the book is that it was very comprehensive. The book covers the low-level details of exactly how to write a test, yet it also manages to address the bigger picture. There is a lot of talk about the why of testing and the principles and strategy behind it. It really puts an emphasis on writing test code that is maintainable.

The Bad

Never have I been so conflicted about a book I’ve read. There is so much good content, but the book is a bear to read. At times it really seems to drag on. I feel like it could be1/3 the size.

At many points, it seems very repetitive to the point where you can predict what he will say next. If you miss something or don’t quite understand it the first time around, just keep reading because it is guaranteed to be covered at least 2 more times.

The organization is rather poor. It seems to jump around a lot. A section at the beginning of the book references a later section, which itself references another section and it is off down the rabbit hole.

The Ugly

In an effort to be very comprehensive, the book seems very indecisive. It presents several different ways to do something without actually making a recommendation. Maybe that is an advantage but there were some places where I personally could use a little more guidance.

Where the book’s indecisiveness really causes problems is when it describes some of the anti-patterns. As an example, on page 63, shared fixtures are introduced. The book mentions that shared fixtures are also referred to as a test smell. It goes on to explain how the benefits of a shared fixture can be obtained by using other patterns. Yet a large portion of the remainder of the book goes into great detail on shared fixtures.

Conclusion

The book contains lots of good information and is worth reading, although maybe not all of it. The first part on strategy and testing philosophy is excellent. As far as the rest of the book I recommend it more as a reference than as a primer. It’s kind of a shame, because I feel like if you got rid of all the duplication, and removed all the details about the various anti-patterns you would have a much lighter and more accessible book.