Thursday, March 1, 2012


Testing programs is a boring thing.It takes lot of time and efforts to do that
but there are easier ways to do that by automated software one such great software is HttpUnit.
HttpUnit is an open source software testing framework used to perform testing of web sites without the need for a web browser.
HttpUnit is primarily designed for "black-box" testing of web sites.
HttpUnit is free software available from HttpUnitSite that implements several useful unit testing methods together with classes for connecting to HTTP servers, processing HTML, and maintaining stateful sessions.

HttpUnit supports :

  • HTML form submission
  • JavaScript
  • automatic page redirection and cookies.
  • Written in Java, HttpUnit allows Java test code to process returned pages as text, XML DOM, or containers of forms, tables and links
It is well suited to be used in combination with JUnit.It easily write tests that verify the proper behaviour of a web site.The use of HttpUnit allows for automated testing of web applications.

The center of HttpUnit is the WebConversation class, which takes the place of a browser talking to a single site.It is responsible for maintaining session context, which it does via cookies returned by the server.To use it, one must create a request and ask the WebConversation for a response.

Some Drawbacks to HTTPUnit:
  • Tests are tied to page structures.
  • If you change your page (say, reordering links or forms), you will break your tests.
  • Test assertions typically depend on the content of the page.
  • If content changes, tests may break.
  • Checking content is not completely sufficient for testing Grid portals.

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.

3. Create a new JUnit test case class:

4. Run your test:

5. View the results:

6. If you have errors double click the row in the JUnit log window to jump to the actual test code that failed.

No comments:

Post a Comment