Extreme Java GUI Testing
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.
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 AuthorThomas 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