Book Review: xUnit Test Patterns
Well, as I related in a post on my personal blog before this shared blog came into being, I was going to read a book every two weeks and give a review of it. I should have said that I’d read 200-300 pages per week instead. My latest book is 800+ pages, and it took me three weeks, even when I skimmed several pieces of it. It was, however, an outstanding book.
If you write software, this book is an absolute must-read. If you’ve never written an automated test, it will convince you why you should. If you’re test-infected, it will give you advice and principles to follow that guide you toward more effective testing and, ultimately, more effective software. For anyone in between, this book has something for you, too. It’s written in a language-agnostic way and has advice applicable to testing with any of the “xUnit” family: any test framework that works along the same lines as Java’s JUnit.
xUnit Test Patterns
Refactoring Test Code
by Gerard Meszaros
As its name suggests, it’s a patterns book, which means that Mike would like it because a large part of it is a catalog of various test-related patterns that the author has collected. Another chunk of the book is taken up by a catalog of test smells. This still leaves plenty of room, though, for Meszaros to provide a thorough introduction to software testing–primarily unit testing, but with plenty of consideration for other test scopes as well–and to give a detailed overview of best practices in testing.
Part One of the book is the narrative, non-catalog part and could be a book all by itself. It covers a lot of theoretical ground with topics like goals of automated testing, guiding principles to consider when writing tests, and various philosophies of testing along with their pros and cons. On the more “practical application” front, there’s a basic introduction to the internal workings of the xUnit family frameworks, which is foundational knowledge for many patterns, and a ton of practical advice revolving around real-world examples of difficult testing situations and methods of dealing with them. You could read just this part of the book–under 200 pages–and come away a better developer for it.
Part Two is the catalog of test smells. Each smell is the formalization of a testing problem that was discussed in Part One. A statement of the problem, its symptoms and possible causes, and various suggested solutions are all collected into a neat, tidy package for easy access. The smells cover a wide variety of things from the seemingly trivial difficult-to-read tests to major systemic problems like unreliable test suites due to sporadic test failures.
Part Three is the pattern catalog, where the solutions to aforementioned problems and best practices are formalized. Each pattern has a brief summary up front, a description of how and when to use it appropriately, examples of how the pattern looks in code (in various languages), and examples of how to refactor problem code to solve the problem effectively with the pattern. The initial summary is highly useful in that you can read through the summaries of all 60 or so of the patterns in a very short time and have a feel for which ones you should look into more deeply for a particular situation.
I have to say one more time that you must read this book! It pulls patterns, practices, and more from many other sources and organizes them all in a well-written, easy-to-read reference that will provide a strong foundation for testing efforts in any xUnit framework. Beyond that, I’ve yet to mention the author’s efforts to establish a common vocabulary of test patterns by assembling them all in one place with a strict system of names. While this may seem trivial in comparison to the content of the patterns, the lack of such a vocabulary can lead to real difficulties in communication when four people use a name like “Test Stub” in four very different ways. Learn a better way.
Get this book. Read it. Use it. Live it.
Related Posts
Comments
5 Responses to “Book Review: xUnit Test Patterns”
Leave a Reply

Wow, my husband used an exclamation point, he must have really liked this book!
Great review Ryan. Good point about test vocabulary. I have heard very different defintions for “integration test” over the years. Common vocabulary makes things a lot easier.
@Welzie – Oh, he definitely discusses the “integration test” in all its colors.
Here is the table of contents. Worth checking out…
[...] Continued here: Book Review: xUnit Test Patterns : Code… [...]