JUnit Recipes – for the gourmets of Java unit testing

A mini-review

The book already has stellar ratings on Amazon, JavaRanch and other select places, and after reading a few chapters, the only thing I can do is add this post on the praise list.

Why only a few chapters ? Well, you see, this is not exactly the type of book that you read from cover to cover, it’s in fact a 720-pages solid collection of JUnit best practices, the most comprehensive you’ll ever found in organized, written form. Until now, I have found precise answers to all my JUnit questions.

The book is organized in three big sections weighting some 200-250 pages each. The first one (‘The building blocks’) is hugely useful if you are a JUnit newbie or even an absolute beginner. It’s a detailed introduction to everything you’ll need to know in order to start using JUnit: basics, usage in mainstream IDEs, testing patterns, managing test suites, test data and troobleshooting advice. Even seasoned programmers will find useful pieces of advice. I especially liked the 5th chapter (‘Working with test data’) : an exhaustive description of all the possible ways of organizing your test data. To be honest, it’s one of the few chapters from the first section, that I’ve really read.

The second part (‘Testing J2EE’) covers testing of XML, JDBC, EJB, web components (JSP, servlets, Velocity templates, out-of-container testing & such) and J2EE applications (security and again some webapp testing – pageflow, broken links, Struts navigation). I can’t really pronounce upon this section since I’ve read only a few subchapters (DBUnit and some related JDBC testing, as well as a few pages from the web testing chapter). But every piece of advice I’ve got was rock solid.

I’ve read in its entirety the third part (‘More JUnit techniques’). Under this bland title you’ll find a group of not-so-common JUnit info such as usage of GSBase addon (funny that I wasn’t aware that such a useful addon exists). There’s also an intriguing ‘Odds and ends’ chapter containing some interesting recipes (here’s a good one for the QA-freaks like me : ‘verify that your test classes adhere to basic syntax rules of JUnit’ – sure, why not ?).

Something that I’ve really missed is a chapter dedicated to mock objects recipes. Yes, there is a quick explanation in the first section – and a reference to Easy Mock or some other mocking API pops now and then in different chapters – there’s even an essay about mocking at the end of the book. But the main mock objects dish isn’t there. I would’ve also loved to see some automated GUI-testing recipes (Abbot, Marathon & related tools). But then again, it’s a >700-pages book so I’m probably asking too much.

To conclude, ‘JUnit Recipes’ is the best JUnit book I’ve ever came into contact with and it supercedes on my list ‘JUnit in Action’. Which, interesting enough, was published by the same Manning almost a year ago. Can’t have too many good JUnit books, don’t they ?