1 / 12

HTTPUNIT

HTTPUNIT. What 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

rory
Télécharger la présentation

HTTPUNIT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HTTPUNIT

  2. What 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.

  3. BSD(Berkeley Software Distribution) license. • Recent Version HttpUnit1.7 • JavaScript support is very basic at present. The near-term goal is full JavaScript 1.1 support. Currently, we do not plan to support browser-specific JavaScript.

  4. 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

  5. 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

  6. 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. For Example: WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest( "http://www.meterware.com/testpage.html" ); WebResponse resp = wc.getResponse( req );

  7. The response may now be manipulated either as pure text (via the getText() method), as a DOM (via the getDOM() method) • WebConversation wc = new WebConversation(); WebResponse resp = wc.getResponse( "http://www.meterware.com/testpage.html" );

  8. 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.

  9. public WebConversation loginToPortal() throws Exception { //WebConversation objects are the cornerstone class. WebConversation wc = new WebConversation(); //We will need to specify the user agent to simulate a browser. ClientProperties cprops = wc.getClientProperties(); cprops.setUserAgent("Mozilla/5.0"); WebResponse resp = wc.getResponse(portalUrl); // Find the login form. // It's not named so we pick it out of an array String frontPage = resp.getText();

  10. //First make sure we are looking at the right web page. assertTrue("Failed to get front page", frontPage.indexOf("Please Login") != -1); WebForm form = resp.getForms()[1]; assertNotNull("No login form found", form); // Fill in form and submit form.setParameter("userName", “admin”); form.setParameter("password", “admin”); form.submit(); // Get logged in page WebResponse resp2 = wc.getCurrentPage(); String page = resp2.getText(); assertFalse("Failed to log in", page.indexOf("Please Login") != -1); return wc; }

  11. Assertion Statement Reference: There is the list of the different types of assertion statements that are used to test your code. • assertNotNull("url: ", url, response) • assertFalse(message, condition) • assertNotNull(object) • assertNotSame(expected, actual) • assertNotSame(message, expected, actual) • assertNull(object) • assertNull(message, object) • assertSame(expected, actual) • assertSame(message, expected, actual) • assertTrue(condition) • assertTrue(message, condition) • fail() • fail(message)

  12. Thank You

More Related