Faq Addition
"Fabio Bertone" <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
I hope this to be the right place to post this:
I have just written a small example of the usage of httpunit/servletunit to
test JSP. Since I found almost no examples on the net, but instead a lot of
questions for examples, I think that maybe you'd like to add it to the FAQ
(http://httpunit.sourceforge.net/doc/faq.html#JSP)
helloworld.jsp, to be placed in the root directory:
<html><body>hello world! I am a JSP! I can multiplicate numbers!
<br>2*2 = <%= 2*2 %>
</body></html>
the test class:
import junit.framework.TestCase;
import com.meterware.httpunit.*;
import com.meterware.servletunit.*;
public class JSPTest extends TestCase {
ServletRunner sr;
public JSPTest(String arg0) {
super(arg0);
sr = new ServletRunner();
}
public void testHelloworld() throws Exception {
ServletUnitClient sc = sr.newClient();
WebRequest request = new PostMethodWebRequest("
http://whateveryouwant/helloworld.jsp");
WebResponse response = sc.getResponse(request);
String responseText = response.getText();
assertNotNull("No response received", response);
assertEquals("content type", "text/html", response.getContentType
());
assertTrue(responseText.indexOf("2*2 = 4") > -1);
}
}
hi,
Fabio Bertone (www.fabiobeta.it)
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop