JUnit Recipes: Practical Methods for Programmer Testing

J. B. Rainsberger (2004)
Review date: November, 2008
Summary

This book is what you would call "reference material". It contains discussions of problem/solution pairs to specific testing problems calling them recipes.

As mandated, the first chapter is dedicated to some testing practices and theory. There's also a small introduction to JUnit to get the reader started. "Elementary tests" is the name of the second chapter, and it contains recipes for seemingly simple tests, such as testing constructors, void methods, and equals(). Chapters 4-6 tell you all you need to know about the mechanics of assembling test suites and executing tests. This is where test parametrization and data externalization is described. Chapter 7 discusses JUnit result processing in detail, while the last chapter in the first part of the book is entirely dedicated to troubleshooting.

The second part is devoted to more specific testing problems. Under the name "Testing J2EE", selected parts of an online store applications are tested. In chapter 9, various ways of using XMLUnit are described. Here we learn about different ways to do XML comparison and verification. Database tests are the topic of chapter 10. It starts with a example of how to decouple JDBC code from business logic using a query builder, and then takes a tour through pretty much everything you'd like to test where a database is involved. DBUnit is introduced here. The next chapter focuses on testing enterprise JavaBeans, outside and inside the container. MockEJB is the main actor here. In chapter 12, HTTP sessions, JSPs, Velocity templates, servlets, and resource filters are attacked. Under the banner "Testing J2EE applications", we learn how to test Struts, EJB security, and transactions in chapter 13. All of this makes up a rather heavy Part 2.

The last part houses miscellaneous topics divided between four chapters: "Testing design patterns", "GSBase", "JUnit-addons", and "Odds and ends". These names accurately correspond to the contents of these chapters.

Finally, there's an appendix section, where the first appendix contains larger snippets of code that could not be squeezed into the chapters, and the second contains some small essays.

Opinion

If you know about 50% of the techniques described in this book, and how to apply them, I'd say you're good at testing! There is not much bad I can say about this book apart from it being little dated and too thorough.

The book covers JUnit 3 and is old enough to address some problems that are non-issues today. Since I haven't read any better book on the topic I don't see this as a problem. Actually it's good to travel back in time to see how some problems were tackled a few years ago, and how the testing frameworks have evolved.

The second disadvantage would be that the book is a bit lengthy. Already when writing the summary I realized that I had to keep it superficial, lest it would get too verbose. Once again, this is not a problem unless you do as I did and read the entire book in one sweep. I seldom say this, but this book really is "reference material" that you browse in search for a specific topic. There are sections, such as the JUnit troubleshooting section, that get quite boring when you see no immediate relevance in reading them.

Apart from these two things, that may or may not irritate you, this is a very good book. The author has spent much time exploring various testing frameworks and delivering the digest. In an exploratory, down-to-earth style the book introduces tool after tool, and technique after technique. The width and depth of this journey is the book's strongest side.

Occasionally it gets too deep: The latter part of section one, where all tests mechanics and JUnit quirks are covered is rather boring, but it could have been relevant when the book was written.

Throughout the book we find some good pointers, such as "don't test the framework", and among them is also a discussion that I must comment on. When covering testing of private methods, the author (or authors) polarize things by dividing the world into public and private methods. Package scope, does not seem to be an option. I find this strange, but this is probably a bug in my understanding of the text, not the book.

As a final note, I can mention that this book manages to pull of a rare feat: Its appendix section, the second part, contains good and informative essays.

As a final word: read this book and get inspired! You can safely skip chapters 3-8 though.

Who should read this book

This is a reference book that should live in every programmer's and tester's book shelf. Those who use JUnit in real-life projects encounter numerous test situations, in which it's not easy to pick the correct strategy. This book is loaded with such strategies, and contains many references to tools that solve specific test-related difficulties. It's as good as it gets.




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.