Java Reference
In-Depth Information
Before demonstrating the Grails framework, let me now discuss the issue of testing web
applications, both in isolation as unit tests and automated integration tests using Gradle.
10.3. Unit-and integration-testing web components
Chapter 6 discussed techniques for unit-testing Java and Groovy classes and demonstrated
how Groovy's mock capabilities provide a standard library of mocks and stubs to support
unit tests. It's easy to test individual classes and to run those tests automatically as part of
a build process.
Testing is so important that most modern web frameworks consider testability a major
design goal, so they try to make the individual components easy to test. For example, one
of the major differences between the original Struts framework and the more modern Struts
2, Spring MVC, JSF, or any of a number of others is how their parts are designed with test-
ing in mind. Despite this, testing of web components is far less pervasive than you might
expect.
Still, unit-testing and integration-testing web applications is as important as testing any-
thing else inthe system, and doingsoautomatically is critical. Integration-testing aweb ap-
plicationbymakingatestermanuallyenterdatainformsandclicklinksisanextremelyex-
pensive and error-prone mechanism. There has to be a better way, and fortunately Groovy
helps a lot in that area.
To lay the foundation, however, I'll begin with a library of mock classes that comes from
one of the biggest Java libraries of them all, the Spring framework.
10.3.1. Unit-testing servlets with Spring
The Spring framework is one of the most popular open source libraries in the Java world.
Chapter 7 on Groovy and Spring discusses it in some detail, but I want to use it here for
two reasons: (1) Spring provides a great collection of mock objects for unit-testing web
applications, and (2) Spring is one of the underlying technologies for Grails, so knowing
more about how Spring works helps you use Grails more effectively.
Search WWH ::




Custom Search