Case Study

Introduction

Next
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 distribution. The code is organized in this manner:

System Under Test
casestudy/src/main
SpringUnit Tests
casestudy/src/test

The tests are packaged under org.springunit.framework.samples.jpetstore in this manner:

domain
Unit tests of domain model objects
domain.logic
Unit tests of business logic using mock objects
dao.hibernate
Integration tests of persistence operations using rolled back transactions
domain.logic.hibernate
Integration tests of business logic with transactions

Next