"Don't you wish there were a knob on the TV to turn up the intelligence? There's one marked 'Brightness,' but it doesn't work." - Gallagher
A couple of interesting things happened recently that sparked some neuron in my brain (I think it was the Halle Berry neuron) to fire and wake me up: I did a piece on my UnBlog about "Sloppy Code, Quality Code", and then got a comment from Jason Bock there about why did I leave out "test coverage". Then, I read on somebody else's blog that Jim Newkirk's new book on Test Driven Development from MSPress was out, and I decided to buy it.
Now, I already knew that Newkirk is the development lead for the PAG / Patterns and Practices team at Microsoft, and also happens to be the dev lead for NUnit v2. So when the book arrived, it didn't take me long to work my way through it.
What you'll hear next is commentary from a developer who believes in the value of Test-Driven Development but who isn't exactly a fanatic about it. Kind of like when I compared Extreme Programming to Scientology in my book review of Extreme Programming Refactored.
This is a relatively small book (About 260 pages including the NUnit tutorial and Appendixes), but that should not be any more cause for disappointment than when refactored code turns out being smaller than what it was before. In fact, you can "get it" from this book by doing nothing more than digesting Chapter 2 thoroughly.
In Chapter 1, Newkirk basically "pays homage to the Gods" in the name of Kent Beck and others (Beck wrote the foreword to the book), but doesn't really succeed in saying much of any real value.
However in Chapter two, Newkirk (and Vorontsov, whose role I cannot fathom) details the refactoring - via Test-Driven Development - of a Stack class. This is the most revealing and valuable chapter in the book as it completely lays out the rules for TDD and refactoring in general.
Chapter 3 is an excellent treatise on refactoring, "by example" that refactors the classic Sieve of Eratosthenes problem and could possibly be one of the best "short" refactoring tutorials out there. The original was definitely "not my code".
The rest of the book is a series of chapters on Tests - customer tests, programmer tests, using Transactions, Service Layer refactoring, and more. You get a thorough understanding of NUnit and how to instrument your code so that NUnit can be fully integrated into the development process, and an excellent tutorial on how to use NUnit at the end of the book.
I recommend this book for several excellent reasons:
- Most developers do not believe in or understand the importance of test coverage and what it will buy them. Developers who read and understand this book will get the big picture, and they will become much more valuable to their employers. (Much more valuable means "you can be paid more".)
- Having a testable, provable code base is indisputably one of the pillars of quality software development. Entire groups (not just PAG) at Microsoft use NUnit and TDD.
- Integrating NUnit and TDD in general into your development process with Visual Studio.NET is easy and this book will show you everything you need to do so. As with any methodology, a serious effort needs to be made to integrate good coding and development habits into your dev group. Because of this, "developer buy-in" is critical. Reading this book helps provide the basis for this with a solid foundation of why TDD is good.
Thanks James and Alexei, for a well done job.