Setting HttpUnit in Oracle JDeveloper

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.

httpunit2:


3. Create a new JUnit test case class:




4. Write the code for your test in the new class.

For example:


public void testPlus() throws MalformedURLException, IOException,
SAXException {
WebConversation wc = new WebConversation();
WebRequest req =
new GetMethodWebRequest("http://127.0.0.1:8990/Application11-httpunit-context-root/faces/calculator.jspx");
WebResponse resp = wc.getResponse(req);
WebForm form = resp.getFormWithName("form1");
assertEquals("1", form.getParameterValue("form1:var1"));
assertEquals("2", form.getParameterValue("form1:var2"));
form.setParameter("form1:var1", "1");
form.setParameter("form1:var2", "2");
assertEquals("2", form.getParameterValue("form1:var2"));
}

5. Run your Web page (this will start the embedded OC4J).

6. Run your test:

httpunit4:

7. View the results:

httpunit6:

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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

me
I'm a Director of Product Management for the Oracle Java Development Tools.
Follow me:
Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today