The Case Study demonstrates how SpringUnit can be used for
both unit and integration testing of a realistic application.
The system under test is the JPetStore, derived from one of the
sample applications distributed with the Spring framework.
In this tutorial, we begin by reviewing the salient features of
the system under test, examining in turn the domain model,
the data access layer and the business logic facade.
Next, we review examples from the object-relational mapping files,
followed by the Spring configuration files by which the application
is wired together.
After reviewing the application implementation, the tutorial
focuses on SpringUnit unit tests, showing simple unit tests of the domain model
objects, followed by unit tests of the business logic objects,
where mock objects are used to simulate the behavior of
classes from the data access layer.
The tutorial concludes with two kinds of integration tests.
First, it shows how to create SpringUnit tests of data access objects
that create, read, update and delete items in the database where
all operations are ultimately rolled back in order to
achieve stateless testing.
Second, it demonstrates SpringUnit tests that perform transactional
operations against the database, in which stateless testing
is obtained through the use of compensating transactions.
The source code for the Case Study is included with the SpringUnit
The code is organized in this manner:
- System Under Test
- SpringUnit Tests
The tests are packaged under
in this manner:
- Unit tests of domain model objects
- Unit tests of business logic using mock objects
- Integration tests of persistence operations using rolled back transactions
- Integration tests of business logic with transactions