The relatively recently released ‘Next Generation Java Testing – TestNG and Advanced Concepts’ by Buest and Suleiman deserves a place on any self respecting developer’s bookshelf, and I personally think this is one of the best-written technical books of the year.
Obviously, this book is about TestNG (co-created by Beust) but even if you use a different unit testing framework like JUnit, the concepts and ideas are very relevant and worthwhile. Unlike some other books that feature specific tools, I was pleasantly surprised that the authors didn’t just try to ram TestNG down the reader’s throat.
The book starts with reasons why TestNG was created and some discussion of the shortcomings of JUnit, although my interpretation of the “Next Generation” part of the title is because TestNG incorporates some aspects of Integration Testing rather than pure Unit Testing which is the focus of JUnit.
Arguments for and against certain testing techniques are prevalent throughout the book, leaving the reader to determine which is best for their own situation. A good example is the authors’ opinion on TDD. Buest and Suleiman suggest that one of the potential pitfalls of TDD is that it promotes micro-design over macro-design but at the same time promotes developers thinking about exit criteria of their code.
One of the more advanced topics covered is JEE testing, and the book shows design patterns on how to test in-container applications (including EJB3) and how to eliminate troublesome aspects of existing code that are hard to test, and which you do not need to test anyway – such as JNDI and JDBC APIs.
All examples start simple and then move on to explain and demonstrate how the idea would work in a real situation. And, as I already noted, the examples are not confined to just the TestNG tool. There are good definitions of various code coverage tools and the different way they work as well as introductions to testing using different frameworks such as Spring, Guice, Selenium and various xUnit frameworks.
The authors’ view on emergent tests is interesting since, coincidently, this was a theme common with the speakers on our ‘Unit Testing a Large Legacy Code Base’ video:
“Unit tests do not have to be written before any other test…they can be derived from functional tests…Some functional tests will be written from requirements and satisfy a core piece of functionality. Over time these tests can be broken up into smaller Unit Tests to narrow down bugs.”
The final chapter, Digressions, I believe is something that should be covered in every technical book. This contains topics that are somewhat connected to the title of the book but not close enough to warrant their own detailed chapter, and also makes a very enjoyable read.
There is a rather large disclaimer at the start of the chapter stating that it is the authors’ opinion only. I found myself either nodding my head in complete agreement with their opinions or gnashing my teeth in complete disagreement.
Their opinion on pair programming is that an expert/novice pairing is unlikely to work, as the expert will get bored and lose motivation quickly. This is surprising to me as, personally, I believe that there is an argument for pair programming to be used as a mentoring technique and a way for expert programmers to help novices.
I can see this book becoming a regular fixture on developers’ desks in the future, regardless of whether they use TestNG or not. I feel this book is more suited to developers who are already unit testing and want to increase their skill set in this area and need some help on more complicated areas to test. If you currently do not perform unit testing then ‘Pragmatic Unit Testing in Java with JUnit’ by Hunt and Thomas is my recommended place to start - or you can wait for my upcoming blog post on a comparison of JUnit, TestNG and FIT.
Leave a comment »