November 20, 2018
Hot Topics:

Extreme Java GUI Testing

  • April 26, 2002
  • By Thomas Hammell
  • Send Email »
  • More Articles »


Testing Web interfaces is also difficult to do with the normal JUnit classes. HTTPUnit solves this problem by providing a set of classes that emulate Web browser behavior, including form submission, basic http authentication, cookies, and automatic page redirection. The main focus of HTTPUnit is the WebConversation class. The idea is that this class provides a way for JUnit test methods to have a conversation with a Web site. The other main classes are WebRequest, which is used to create an HTTP request, and WebResponse, which is used to store the results of a request.

HTTPUnit also provides classes that allow test methods to view the WebResponse in a number of ways. A WebResponse can be viewed by:

  • Getting the actual input stream of the response and parsing through it.
  • Converting the return HTML into an XML DOM and then parsing and searching it as an XML document.
  • The HTML forms, tables, and links can be viewed as a collection of HTTPUnit WebForms, WebTables, and WebLinks.

Let's look at a simple Web application and HTTPUnit. This application is a simple airline reservation system that shows a user the flights that he has booked and allows him to book additional flights. There are three Web pages. The first page is a login screen, where the user enters his name. The second screen shows the list of flights that the user presently has reservations on. These screens are shown in Figures 2 and 3 below. The third screen shows a list of available flights given a set of airports and date of flight. It is show in Figure 4 for a flight from San Francisco to Newark on 3/30.

Figure 2

Figure 3

Figure 4

If you were to test this application manually, you would go the login screen, enter a user name, then verify that the flights listed were correct for that user. Then you would try to add a new flight for that user.

Let's see how this could be done automatically using HTTPUnit. (The full set of source for all applications and unit test can be downloaded at


About the Author

Thomas Hammell is a senior developer at Hewlett-Packard and is part of the Telecom Infrastructure Group, which develops various tools used to Web-enable telecom applications. He has over 17 years of experience in developing software. Hammell has published a number of articles on Java topics ranging from Swing development to Unit testing and presented a session, Extreme GUI Testing, at the JavaOne Conference in March, 2002. Tom holds a Bachelor of Science in Electrical Engineering and Masters of Computer Science from Stevens Institute of Technology.

      Page 2 of 2

      Comment and Contribute


      (Maximum characters: 1200). You have characters left.



      Enterprise Development Update

      Don't miss an article. Subscribe to our newsletter below.


      Thanks for your registration, follow us on our social networks to keep up-to-date