This chapter described testing of servlet-based Web applications on three different layers:
Functional tests, using HttpUnit, involve only those pages of a Web application that can be addressed over HTTP.
White-box integration tests on the server, using Cactus, participate in the execution of servlets and JSPs, and allow access to the internal objects of the servlet API.
Server-independent tests, using dummy and mock objects, allow testfirst development of servlets.
Function tests for a Web interface are required in all of these cases, whereas there is a choice of different testing technologies. To create expensive integration tests, like those supported by Cactus, it appears worth-while to wait until we actually hit recurring deployment and integration problems. However, this optimistic waiting means that there is a reassuring test suite handily available for the single servlets.
In addition, this chapter introduced an approach on how to separate a servlet's logic from the servlet API to improve testability. Finally, we discussed several ways to generate HTML and how to test this code.
This chapter showed that test-first development is also possible for Web applications. Once more, we noticed that the use of mock objects can contribute to decouple classes and thus to improve the design.