Book Review: Pragmatic Unit Testing


Title: Pragmatic Unit Testing
Authors: Andrew Hunt, David Thomas
ISBN: 0-9745140-2-0
pages: 150

This book gives a good introduction into the different aspects of unit testing. It’s easy readible and aims on developers without much (any) unittest experience (but it’s also worth reading for developers with more experience). The authors are very clear that unittesting improves the code, makes your live as a developer easier and supports a growing understanding of your application. They also make it clear that unittests must be considered as real code, so it must be subject to the same standards as your application code.

They choose a very pragmatic approach: why should I test, what should I test and how should I test. The balance between theory and code is good. No endless theorizing and also no endless API descriptions. The theory is short, comprehensive and to-the-point and contains a good overview of the concepts of JUnit based frameworks. The code is more or less real code, it’s comprehensive and illustrates the point the authors are making.

The authors provide guidelines on what aspects of the code you test and how you can do that. Many bugs occur around “boundary conditions” so they dedicate a chapter to that subject. Another chapter is dedicated to the use Mock Objects.

Unittests are very powerful, but if used badly you’ll waste your time maintaining and debugging the unittests themselves while they do not provide the confidence that the code is doing what it ought. Good unittests conform to following properties:
Automatic : Invoke the test en check the result automatically.
Thorough : Test (only) everything that is likely to break.
Repeatable : Every test should be able to run over and over again, in any order, and produce the same results.
Independent : Test should be independent from the environment and other tests.
Professional : Unittest code is real code, so it must conform to the same standards as the application code.

Finally, a chapter is dedicated on embedding unittesting in a project.

I can recommend this book to everybody (actually, I would say it’s almost mandatory). It’s easy accessible, it’s pragmatic, it’s motivating and it really gives you a good overview of the different aspects of unittesting and, most important, does not scare you away by making it too complex.

The version in our library is based on C# (instead of the java version) and NUnit. But that’s absolutely no excuse for skipping the book.

The pragmatic programmer
Java book site

About Author

Aino Andriessen is principal consultant and expertise lead 'Continuous Delivery'. His focus is on Oracle Fusion Middleware ADF and SOA development, Continuous Delivery, architecture, improving the software development proces and quality management. He is a frequent presenter at Oracle Open World, ODTUG Kaleidoscope, UKOUG Technology Conference and OUGN Vårseminar. He writes articles and publishes at the AMIS technology blog (

Comments are closed.