« A Pattern By Any Other Name Would Still Sell As Well | Main | Review: XPlanner »

March 16, 2004

Review: JUnit In Action

This review is one I wrote for my company's internal newsletter, but as I haven't signed any exclusivity deals with them, I thought I'd release it to the unwashed masses, so to spreak.

JUnit in Action is written primarily by Vincent Massol - the creator of the Cactus server-side testing framework and a contributor to both the Maven and Mock Objects projects. Not surprisingly then, the book does spend the majority of it's post-introductory chapters using these tools in the context of testing a hypothetical J2EE application. It's worth stating up front that other JUnit descendents like HttpUnit and HtmlUnit only rate a passing mention and no examples of their use are included.

I came to purchase this book after having read early versions of the chapters covering mock and stub objects several months ago. I was most impressed with these chapters and brought the book expecting more of the same quality. Whilst I wasn't disappointed with the rest of the book, I do believe that these chapters are still the most compelling and are not exceeded
by anything else in the book.

As typical of the range of "In Action" books, each chapter is thick with code examples and whilst I find this technique disrupts the flow of the text somewhat, it makes the 330+ pages a fairly quick read. The author's style is both straightforward and easily understood, making the book amenable to reading short sections at a time.

The first section of the book introduces vanilla JUnit, the philosophy behind unit testing in general and briefly mentions TDD - although more as an alternative than a mandate. This entire section (117 pages) could be skipped by anyone with any experience in JUnit unless the final chapter on integrating JUnit with Ant, Maven and Eclipse is of interest.

The second section is the highlight of the book in my opinion as it begins with the stubs and mock objects chapters mentioned earlier in this review. In addition, the Inversion of Control pattern is introduced along with some great testing philosophy including a section on test code being a "first order client" of application code that completely changed the way I viewed test design up to that point. I strongly recommend anyone who hasn't read the PDF versions of Chapter 6 (Stubs) and Chapter 7 (Mock Objects) to do so if they're in anyway unfamiliar with these topics. Finally, Cactus is introduced as a general framework for unit testing server side components and as a precursor to the next section.

The final section is dedicated to approaches to testing a typical J2EE application's components. Various techniques for testing JSPs, servlets, EJBs (session beans, entity beans and message beans) and database access code are presented using Cactus or basic JUnit and often in combination with mock object frameworks (Mock Objects and DynaMock). Along with the pragmatic "how-to" nature of this section, there are liberal inclusions of "Unit testing best practice" sidebars (throughout the book) to isolate/highlight the salient points of the current section. Whilst many of these items are bleedingly obvious, either from the accompanying text or past experience, it is an effective technique nonetheless. A collection of these annotations itself would form a useful list for any Java developer.

Across the entire book, the author's knowledge in the server-side Java testing realm is obvious and further highlighted by the many good points on test design and philosophy he intersperses with the practical examples. This information is probably the most valuable and would be very handy for people starting to put together a unit testing strategy for a new project or looking to refactor an existing application's test suite.

In conclusion, I would recommend this book for a developer first coming to Java unit testing but there is probably too much of an overview perspective to the book (understandable, given the ambitious scope covered) to make it a mandatory item for an experienced Agile developer. If you're still interested, sample Chapters 6 and 7 to see whether the level of information is right for you.

More information (including TOC and other sample chapters) can be found at http://www.manning.com/massol/.

Posted by Andy Marks at March 16, 2004 07:11 AM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?