5.1. An Introduction to HTTPUnit
The problem of testing Web sites is so ubiquitous and so important that a set of tools called HTTPUnit Listing 5.1.
[1] The name comes from Hypertext Transfer Protocol, the protocol used between Web servers and clients.
Listing 5.2. A simple HTTPUnit test
Listing 5.1.Note that WebTest1 extends TestCase, so it may be run the same way that the examples in Chapter 4 were run. HTTPUnit exists as a set of add-on classes to JUnit, so all the points made about how and what to test still hold.
package com.awl.toolbook chapter05;
import junit.framework.*;
import com.meterware.httpunit.*;
public class WebTest1 extends TestCase {
public void testGet() throws Exception {
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(
"http://localhost:8080/toolbook/chapter05/sample.jsp");
WebResponse res = wc.getResponse(req);
assertTrue(res.getText().indexOf("Hello") != -1);
}
}