contents

preface
preface to the first edition
acknowledgments
about this book
about the authors
about the cover illustration

Part 1 JUnit essentials

Chapter 1 JUnit jump-start
Proving it works
Starting from scratch
Understanding unit testing frameworks
JUnit design goals
Setting up JUnit
Testing with JUnit
Summary
Chapter 2 Exploring core JUnit
Exploring core JUnit
Running parameterized tests
JUnit test runners
Composing tests with a suite
Summary
Chapter 3 Mastering JUnit
Introducing the controller component
Let’s test it!
Testing exception handling
Timeout testing
Introducing Hamcrest matchers
Setting up a project for testing
Summary
Chapter 4 Software testing principles
The need for unit tests
Test types
Black box versus white box testing
Summary

Part 2 Different testing strategies

Chapter 5 Test coverage and development
Measuring test coverage
Writing testable code
Test-driven development
Testing in the development cycle
Summary
Chapter 6 Coarse-grained testing with stubs
Introducing stubs
Stubbing an HTTP connection
Stubbing the web server’s resources
Stubbing the connection
Summary
Chapter 7 Testing with mock objects
Introducing mock objects
Unit testing with mock objects
Refactoring with mock objects
Mocking an HTTP connection
Using mocks as Trojan horses
Introducing mock frameworks
Summary
Chapter 8 In-container testing
Limitations of standard unit testing
The mock objects solution
In-container testing
Comparing stubs, mock objects, and in-container testing
Summary

Part 3 JUnit and the build process

Chapter 9 Running JUnit tests from Ant
A day in the life
Running tests from Ant
Introducing and installing Ant
Ant targets, projects, properties, and tasks
Putting Ant to the task
Dependency management with Ivy
Creating HTML reports
Batching tests
Summary
Chapter 10 Running JUnit tests from Maven2
Maven’s features
Setting up a Maven project
Introduction to Maven plug-ins
The bad side of Maven
Summary
Chapter 11 Continuous integration tools
A taste of continuous integration
CruiseControl to the rescue
Another neat tool—Hudson
Benefits of continuous integration
Summary

Part 4 JUnit extensions

Chapter 12 Presentation-layer testing
Choosing a testing framework
Introducing HtmlUnit
Writing HtmlUnit tests
Integrating HtmlUnit with Cactus
Introducing Selenium
Generating Selenium tests
Running Selenium tests
Writing Selenium tests
HtmlUnit versus Selenium
Summary
Chapter 13 Ajax testing
Why are Ajax applications difficult to test?
Testing patterns for Ajax
Functional testing
JavaScript testing
RhinoUnit versus JsUnit
Checking best practices with JSLint
Testing services with HttpClient
Testing Google Web Toolkit applications
Summary
Chapter 14 Server-side Java testing with Cactus
What is Cactus?
Testing with Cactus
Testing servlets and filters
Testing JSPs
Testing EJBs
What is Cargo?
Executing Cactus tests with Ant
Executing Cactus tests with Maven2x
Executing Cactus tests from the browser
Summary
Chapter 15 Testing JSF applications
Introducing JSF
Introducing the sample application
Typical problems when testing JSF applications
Strategies for testing JSF applications
Testing the sample application with JSFUnit
Using HtmlUnit with JSFUnit
Performance testing for your JSF application
Summary
Chapter 16 Testing OSGi components
Introducing OSGi
Our first OSGi service
Testing OSGi services
Introducing JUnit4OSGi
Summary
Chapter 17 Testing database access
The database unit testing impedance mismatch
Introducing DbUnit
Using datasets to populate the database
Asserting database state with datasets
Transforming data using ReplacementDataSet
Creating datasets from existing database data
Advanced techniques
Database access testing best practices
Summary
Chapter 18 Testing JPA-based applications
Testing multilayered applications
Aspects of JPA testing
Preparing the infrastructure
Testing JPA entities mapping
Testing JPA-based DAOs
Testing foreign key names
Summary
Chapter 19 JUnit on steroids
Introduction
Transparent mock usage
DbUnit integration
Assertions made easy
Using reflection to bypass encapsulation
Summary
appendix A: Differences between JUnit 3 and JUnit 4
appendix B: Extending the JUnit API with custom runners and matchers
appendix C: The source code for the book
appendix D: JUnit IDE integration
appendix E: Installing software
                     index