Expert Spring MVC and Web Flow

(Dana P.) #1
The AbstractTransactionalSpringContextTestsextends the Dependency Injection test
by managing a transaction for each test method. By default, a transaction is created before
each test method and then rolled back afterward, to ensure that the outside “world” was not
permanently changed. This class, however, requires a PlatformTransactionManagerin the
ApplicationContextto be able to manage the transactions.

Testing Summary


Spring MVC applications are highly testable, due to their use of interfaces, Dependency Injec-
tion techniques, and decoupled designs. Both unit and integration tests can easily be written
to test not only the domain model, but all layers of the application. The Spring Framework
provides many classes inside spring-mock.jarto help with test creation and management. In
combination with mock objects, the tests for your web components and other layers can pro-
vide immediate feedback for new features and refactorings. This leads to higher confidence in
the system, and thus a greater ability to adapt the system to growing needs and requirements.
Above all, remember that tests should always run fast, whether you are testing a simple
POJO or a complex web Controller. Tests that run fast are tests that are built and run during
development, when they can catch issues earliest.

308 CHAPTER 10 ■TESTING SPRING MVC APPLICATIONS

Free download pdf