Chapter 12. Testing web components
This chapter covers
- Testing HTTP session data
- Testing static and dynamic web pages
- Testing JSP components
- Testing servlet code
- Testing dynamic data before it is displayed
- Using ServletUnit to simulate the web container
In this chapter we provide recipes for testing web components in isolation, rather than testing the web application as a whole. We divided the chapters this way because we use different technologies and approaches to test a web application than we do to test its components—the servlets, JSPs, Velocity templates, and what have you that make up the application. In short, we test web applications from end to end using HtmlUnit, something described in detail in chapter 13, “Testing J2EE Applications,” but we use plain old JUnit and ServletUnit[1] to test web components in isolation—that is, without a container and, if we can, without invoking any business logic. How do we do it?
1 Part of the HttpUnit project (http://httpunit.sourceforge.net). Do not confuse this with the defunct project of the same name.