Book Review: The Art of Unit Testing


Book Review: The Art of Unit Testing

A review of Roy Osherove’s The Art of Unit Testing with Examples in .NET

Executive summary: buy and read this book.

The good:

Chapters 7, 8, and 9 are excellent. These cover how to write good tests, how to get your organization to adopt unit testing, and how to work with legacy code. The table on p. 232 ("Team progress and output measured with and without tests") and the test-feasibility table on p. 241 are priceless.

Appendix A covers designing for testability. I’ve only skimmed the appendices, but this hits the important topics: Inversion of Control, issues with Singletons, etc.

Appendix B has great coverage of tools and frameworks related to testing, including Moq (one of my favorites).

The disappointing:

Chapter 3 generally recommends property injection over constructor injection. I don’t agree with this, but that’s open for debate. What I find glaring is the book’s failure to mention the need to check if dependencies are assigned. This is more challenging with optional dependencies injected via properties. His techniques seem prone to NullReferenceExceptions. I can understand omitting checks from example code, but I did not find a discussion of this topic in the text.

Chapter 5 contains an extended discussion of the old, verbose record-and-replay syntax in Rhino Mocks. Much less coverage is given to the new Arrange, Act, Assert (AAA) syntax.

Similarly, some examples use anonymous delegates. While this might make the material more accessible, I prefer the cleaner syntax of lambda expressions.

I came away from the early chapters with the impression that they were excessively pragmatic. (Now I’m having difficulty coming up with examples to substantiate this.) Later chapters stressed best practices, though.

Final notes:

Read the author’s blog entry on Steal My Book. Hopefully this will make you angry (not at him!) and will encourage you to purchase his book.

Your Host:
Copyright © 2000-2013 by William Sorensen. All rights reserved.