How to Test Java Script by Using HttpUnit

How to Test Java Script by Using HttpUnit thumbnail
Use HttpUnit to retrieve web page data and test your code.

The HttpUnit library is a group of functions and properties you can use to request website data from your JavaScript code. The HttpUnit library adds the ability to retrieve other web pages in your code, parse the data and display it on your page. You can also use the HttpUnit library to test your JavaScript code. If you retrieve a web page and no data is returned, then you know there is an error in your JavaScript functions.

Instructions

    • 1

      Add the HttpUnit library to your code. This allows you to use the HttpUnit functions and properties. The following code adds the libraries:

      import com.meterware.httpunit.*;

    • 2

      Initialize your "WebConversation" variable. This is the HttpUnit variable used to retrieve a web page. The following code creates the variable:

      WebConversation convo = new WebConversation();

    • 3

      Retrieve the web page. The "WebConversation" variable calls the web page and assigns it to the "WebResponse" variable. The following code calls a web page:

      WebResponse resp = convo.getResponse( "http://www.domain.com/webpage.html" )

      Replace "http://www.domain.com/webpage.html" with the page you want to call.

    • 4

      Write the response to the page. If the HttpUnit test succeeds, data written to the screen is the code for the remote web page. The following code writes results to your screen:

      System.out.println( resp );

Related Searches:

References

  • Photo Credit computer image by blaine stiger from Fotolia.com

Comments

You May Also Like

Related Ads

Featured