Software testing is indispensable and is one of the most discussed topics in software development today. Many companies address this issue by assigning a dedicated software testing phase towards the end of their development cycle. However, quality cannot be tested into a buggy application. Early and continuous unit testing has been shown to be crucial for high quality software and low defect rates. Yet current books on testing ignore the developer's point of view and give little guidance on how to bring the overwhelming amount of testing theory into practice. Unit Testing in Java represents a practical introduction to unit testing for software developers. It introduces the basic test-first approach and then discusses a large number of special issues and problem cases. The book instructs developers through each step and motivates them to explore further.
Shows how tests written before the application is coded can ensure quality and evolutionary design.
Tackles difficult topics such as persistency, concurrency, distribution, and web applications.
Includes a discussion of testing with C++ and Smalltalk.
Review By: Harmon Avera, Jr. 07/08/2010"Unit Testing in Java" is an excellent introduction to the philosophy and implementation of test-first software development. Using Java-based JUnit as the testing framework, this book presents solutions to real-world testing scenarios in a readable and useful format. It will help anyone implement a successful development environment using the test-first philosophy of Extreme Programming.
Although fairly short, the book is packed with sample code as well as explanations and usage. The book is easy to read, but requires two readings (at least for me) to get the full benefit. The book is organized into three major sections – Basic Techniques, Advanced Topics and an Appendices section.
The Basic Techniques section reads like a textbook teaching test-first development. The authors discuss the importance of test automation and introduce the JUnit framework used to implement automation. Then they lay out the basic steps of test-first development, with recommendations on how to handle inter-unit dependencies and how to organize and run tests. One chapter covers test ideas and heuristics, such as black/white box testing, testing typical functionality, threshold values, and equivalence classes; testing errors/exceptions; and object interactions. Another chapter describes dummy and mock objects and how they maintain test independence. The next chapter discusses the effect of inheritance and polymorphism on test design. The section's last chapter discusses the real-world question, "How much testing is enough?"
The Advanced Topics section is a collection of independent chapters that can be consulted based on need or interest. The chapter topics include persistent objects, concurrent and distributed systems, Web applications, testing GUIs, and how-to-do unit testing under different (non-XP) development processes.
The appendices include notes and FAQ specific to JUnit and its extensions; unit testing frameworks for other languages, including SmallTalk and C++; and a glossary and bibliography/list of references.
The authors use many small samples throughout the text. Sample code is mixed with the text, but, as the testing environment grows from simple units to sub-systems with multiple dependencies, it is easy to understand and follow the development of increasingly complex tests.
The chapters in Section 1 should be read sequentially, while the chapters in Section 2 are designed to be independent and can be read and used in any order. The sample code in this section is often several pages long because of the subject presented.
In addition to an excellent technical presentation of unit-test design and implementation, the authors show an understanding of the human element of testing. For instance, in the chapter titled "Persistent Objects," they describe several techniques for speeding up the test suite. They recognize that if unit tests take too long to run, the developer won't run them.
As a developer currently using Java and JUnit, I really enjoyed reading this book because it is understandable and several chapters are especially useful for my work. However, I also think the book can help anyone understand and implement a successful Java-based development environment using the test-first philosophy of Extreme Programming.
My recommendation is to read this book and use its ideas in your software development!