||New Reviews| |Software Methodologies| |Popular Science| |AI/Machine Learning| |Programming| |Java| |Linux/Open Source| |XML| |Software Tools| |Other| |Web| |Tutorials| |All By Date| |All By Title| |Resources| |About||
Keywords: Java, unit testing, TestNG, software development
Title: Next Generation Java Testing
Author: Cedric Beust and Hani Suleiman
Publisher: Addison Wesley
Verdict: Highly recommended
Most technical books fall into one of two categories: either extolling a particular language, framework or tool or else a book on a particular process, development technique or theory. In the case of 'Next Generation Java Testing' we've got a book that does a bit of both. On the framework side of things the book looks at TestNG, a Java testing framework that goes beyond the current de facto choice of JUnit. And on the process side of things we have a book that dares to suggest that there are limitations in the whole idea of unit-testing in the context of Test-Driven Development.
The book begins with JUnit 3, which for a long time was considered state of the art in unit testing. It describes a number of usage scenarios which high-light some of the perceived weaknesses in current unit testing strategies, particularly the idea that tests should be stateless. Then there is the problem of wanting to run only one test out of whole suite, or perhaps wanting to re-run only those tests that failed. This, along with a number of other issues, leads to an introduction to TestNG (which has been an influence on the latest version of JUnit). Not only does this address the problems that the authors have high-lighted, it also takes advantage of Java annotations, allows greater emphasis on object orientation and uses a fairly basic XML file for easy and flexible configuration.
This introductory chapter is followed by a long (125 pages give or take a few) and detailed chapter on testing design patterns. It's one hell of a chapter, and if we're honest it could have been broken up into a number of smaller and more self-contained chapters. But that's a minor criticism given the content. It covers a range of testing patterns, including testing multi-threaded code, data-driven testing, performance testing, mocks and stubs, test groups, code coverage and more. In general the approach is very focused on real-world scenarios, and there's plenty of sample code to illustrate the patterns being described.
The next two chapters look at enterprise and JEE testing, again combining real-world scenarios with sample solutions and a good use of code. Tricky topics, such as in-container versus out-of-container testing, database testing using JDBC, XML and so on are explored. The use of other tools, such as XMLUnit and Spring, is touched on where necessary. The chapter entitled Integration looks at the world beyond your Java code and covers Swing, HTML, more on databases, continuous integration etc.
Chapter 6 turns its attention to extending TestNG, which includes information on how Beanshell Scripting, (the original Java scripting language), can be used to further extend or automate TestNG. There is also material on creating custom annotations and how to use the Reporting API.
It's when you get to chapter seven (entitled Digressions) that there polemical tone goes up another notch. It describes some of the fundamental limitations of Test-Driven Development (TDD). The authors make it clear that they are not interested in controversy for the sake of it, the issues they have with TDD are the result of experience rather than ideology. It makes for thought-provoking reading and provides a counter-weight to those who would push TDD as the solution to developing solid code.
In all this is a book that does a great job of both covering the features of TestNG, showing how it can be used to solve many complex (and not so complex) unit testing problems and in making the reader think long and hard about the place of unit testing in the grand scheme of things. It's one of the most interesting and thought-provoking Java development books we've seen in a while here at TechBookReport.