The Art of Unit Testing: With Examples in .Net

Roy Osherove (2009)
Review date: April, 2011
Opinion

I can start immediately by saying that I really like this book. The author has managed to add his own deep knowledge of the domain to existing sources, such as Martin Fowler's refactoring book and Michel Feather's book on legacy code, and Gerard Meszaros bible on test patterns (if I remember correctly). This makes the book cover a lot of ground, so it's a very good intro book. It's easy to read and well-structured. I also like the recurring "Definition" boxes that sometimes define concepts that are not commonly defined.

This is also one of these books that contains quite a few gems, or points I'd like to emphasize.

One such point is naming of test methods. Simple, yes, but not discussed in many other books. The suggested scheme is [MethodName]_[StateUnderTest]_[ExpectedBehavior]. Not rocket science, but I've struggled with this on many occasions, and giving such concrete advice in an introductory book is a very good idea.

Another thing I like is the explanation of mocks. If you've read a couple of books on developer testing, you're likely to have encountered several definitions of mocks and stubs. In this book, the author is very clear about this: assertions are made on a mock. A mock can make a test fail, a stub cannot. Use one mock per test!

On the whole, I'd say this book the best introduction to mocking I've read, and before that comes a very good summary of seam-related techniques (from Michael Feather's book). This gives roughly 120 pages of quality reading.

The book also contains a nice comparison between different mock frameworks for .NET. Good summary.

Towards the end of the book is a chapter about organizational issues related to unit testing. It contains answers to "tough questions" and treats other "company-related" aspects of unit testing. By adding this chapter, which is very good by the way, the author has turned this book into a self-contained body of knowledge on unit testing based on current best practices. I also respect that he hasn't fallen into the trap of writing yet another TDD book. Yes, test-driven development is mentioned from time to time, but it certainly doesn't take over.

Since I can't come up with anything distinctly bad to say about this book, I have to pick an inaccurate statement at least. Somewhere the author claims that not many people know what inversion of control is, and what it takes to make it happen. Now, that's not entirely accurate, though it might have larger bearing for the Microsoft platform, especially in 2009. Nevertheless, he's right in his prediction about IoC becoming popular in conjunction with testing.

On the whole, I think this is a very good book with a very high info/page ratio, and I'd dare say that even an experienced developer might find something of value in there. I certainly did. Just get it.

Who should read this book

This book is a small, self-contained body of knowledge on unit testing, mocking, legacy code, and .NET-specific frameworks and techniques. If you need to pick up either, this book is for you.




News

  • 2015-09-29

    It's been almost one and a half year since I reviwed a book! I've been too absorbed by Writing my own. Anyway, I'm back with Jeff Patton's relatively...
  • 2014-01-04

    New category! Performance! Reviewed The Every Computer Performance Book. Check it out!
  • 2013-09-10

    Reviewed a book that' slightly less technical, but much more fun to read. It's I.T. Confidential.
  • 2013-08-13

    Reviewed yet another book on Visual Studio 2012 and TFS. I also created a "Microsoft" category and moved the other TFS book there from the "Tools"...
  • 2013-08-05

    Updated the FAQ. Included information about getting a book reviewed.