Setting HttpUnit in Oracle JDeveloper
By Shay Shmeltzer-Oracle on Aug 09, 2007
One way to test Web application is with HttpUnit framework that is based on Junit. One nice thing about JDeveloper is that because of the built-in support for JUnit you also get a nice HttpUnit testing environment.
Here are the steps to follow.
1. Download HttpUnit and extract it to your drive.
2. In JDeveloper take your Web project and go into project properties->libraries. Click the "Add JAR" button and add the files from the lib and jars directory.
3. Create a new JUnit test case class:
4. Write the code for your test in the new class.
public void testPlus() throws MalformedURLException, IOException,
WebConversation wc = new WebConversation();
WebRequest req =
WebResponse resp = wc.getResponse(req);
WebForm form = resp.getFormWithName("form1");
5. Run your Web page (this will start the embedded OC4J).
6. Run your test:
7. View the results:
8. If you have errors double click the row in the JUnit log window to jump to the actual test code that failed.
A few other tips.
1. HttpUnit requires you to understand the structure of the HTML page you are testing. One nice trick I use is to copy the source of the HTML page from the browser and paste it into a new HTML file in JDeveloper, then I can use the visual designer and structure pane to find out exactly the components I need to check.
2. Remember that if you want to monitor the HTTP messages, you can use the built in HTTP monitor in JDeveloper.