||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, J2EE, JUnit, unit testing
Title: Test-Driven Devlopment : A J2EE Example
Author: Thomas Hammell, with Russell Gold and Tom Snyder
Level: Intermediate Java
Verdict: If you ever wanted to apply test-driven development but wanted more than the simplistic examples provided in many agile development books then this is the book for you
Unit-testing is a core practice in most agile software methodologies. Indeed it should be no surprise that Kent Beck, one of the founders of extreme programming (XP), was also one of the authors of the JUnit testing framework (the other being Erich Gamma). However, for many developers the idea of test-driven development (TDD) seems counter-intuitive. Why write a test before you've written the code to be tested? Why code a test that fails when it would appear to be more efficient to build the code and then add the test afterwards. And how exactly does building lots of simple unit tests help drive the design and development of a complete application?
It's these questions, and more, that are addressed in this slim little book from Apress. Now, most books on agile methods will include some coverage of unit testing, usually based on one of the xUnit frameworks, but this coverage is generally not to any great depth nor does it help bridge the gap between the micro-scale of an individual unit test and the big picture of a complex real-world application. This is where this book scores highly, in that it not only details a range of testing tools but also shows how these fit in with the overall design of an application and also how it relates to functional and GUI-testing.
The book is structured around a basic J2EE application that uses a mixture of platform technologies: servlets, JDBC for data access, JSP for the web front end, Swing for the rich client and so on. Note the Java bias, although there are xUnit tools for other programming languages and platforms this book is very Java-centric, as the title makes clear, this is about TDD for the J2EE platform. The range of technologies used is useful in that it mirrors the complexities of a real application and also allows the authors to showcase a range of testing approaches beyond the basics of JUnit (and Ant for an automated test and build process).
Testing servlets, for example, is discussed in some detail and the problems of testing within a container are explored in some detail before the use of Mock Objects is introduced. Similarly the problems of testing databases is also discussed and it is shown that using a tool like dbUnit can simplify things considerably. By showing how even tricky areas can be tackled using the right tools the book succeeds in showing that testing can be extended into each of the different technologies/layers of an application.
Of course that isn't to say that there aren't still difficulties, and one of these remains testing a GUI. Here two tools are used, JFCUnit and Jemmy. As with all of the other tools, there is plenty of sample code used to show how the tools are used. The strengths and weaknesses of each is also discussed so that the reader has the background info required to assess how it can be used in his or her own projects.
It's worth pointing out that the book also includes plenty of hands-on exercises, and that an appendix of around 70 pages provides solutions and example code. This is a sizeable chunk of the 278 page text.
Finally, there are two chapters which focus on wider concerns. One looks at how to improve the entire test-driven process and the other looks at how to transition an organisation to TDD. These usefully round off the what is a short, readable and extremely useful guide. If you ever wanted to apply test-driven development but wanted more than the simplistic examples provided in many agile development books then this is the book for you.