Functional Testing with HttpUnit

The chapter explains the techniques for performing functional testing of Web apps with the HttpUnit framework. The chapter opens with a consideration of the role of functional testing in XP; it then explains how to use the HttpUnit tool. The chapter concludes with a case study covering the development of a link-checking spider using HttpUnit.

Why Functional Testing?

HttpUnit is not unit testing at all. HttpUnit more closely approximates functional testing, or black-box testing. Web app tests written using HttpUnit do not test pieces of the app code but rather query the Web server externally and examine the responses received. Extreme Programming does not usually focus on this sort of testing, because of its inherent complexities. Testing an entire Web app can be a daunting task; many different combinations of user behavior exist, and attempting to replicate them all seems difficult. Faced with the challenge of writing code that verifies each possible permutation of "The system could not process your request because…," programmers will hide out in the nearest dark room and attempt to port Linux to the Sega Dreamcast, instead. So XP focuses on unit testing—testing small, manageable pieces of code so that each building block of the system is verified as being good. However, functional testing holds an important place in Extreme Programming. XP stresses that functional tests are written for (and largely by) the customer so that they receive high-level feedback about the state of the system. Because functional tests verify the whole system, they can catch subtle bugs that emerge only in a close-to-production environment (server configuration issues, subsystem-interaction bugs, user-experience issues, and so on). As a system matures (and XP says that the natural state of a project is in deployment), it becomes more possible (and necessary) to devote time to ensuring that the system performs as expected. Automated functional tests relieve someone (even, gasp!, a developer) of the grim duty of manually inspecting unchanged areas of the site before a new build is released to production. Furthermore, in a Web environment, the line between unit and functional testing blurs. Because each request-response cycle is somewhat atomic, a page view can be treated as a "unit" of code. Testing that sales_report.jsp returns a view of sales reports is a legitimate verification of a component. Also, when using technologies such as JSP, testing the raw HTML output may be the only useful way to determine whether a component has behaved as expected.

Java Start Sidebar
Where to Get HttpUnit

HttpUnit is an open source, automated Web site testing tool created by Russell Gold. HttpUnit is written in Java and is distributed for free on SourceForge at:

Java End Sidebar