jWebUnit

0

During my current project, i encountered jWebUnit, a unittesting framework based on jUnit and HttpUnit. Old news for some, new for me.
Since we already had some posts on jUnit and HttpUnit, i thought this might be of interest.
An example of its conciseness (as found on the jWebUnit homepage):

Old code (jUnit & HttpUnit):

   public void testSearch() throws Exception {
      WebConversation wc = new WebConversation();
      WebResponse resp = wc.getResponse( "http://www.google.com");
      WebForm form = resp.getForms()[0];
      form.setParameter("q", "HttpUnit");
      WebRequest req = form.getRequest("btnG");
      resp = wc.getResponse(req);
      assertNotNull(resp.getLinkWith("HttpUnit"));
      resp = resp.getLinkWith("HttpUnit").click();
      assertEquals(resp.getTitle(), "HttpUnit");
      assertNotNull(resp.getLinkWith("User's Manual"));
   }

New code, using jWebUnit:

   public void setUp() {
      getTestContext().setBaseUrl("http://www.google.com");
   }

   public void testSearch() {
      beginAt("/");
      setFormElement("q", "httpunit");
      submit("btnG");
      clickLinkWithText("HttpUnit");
      assertTitleEquals("HttpUnit");
      assertLinkPresentWithText("User's Manual");
   }

For more information, see http://jwebunit.sourceforge.net/

Share.

About Author

Comments are closed.