HttpUnit « Test « Java Articles

Home
Java Articles
1.Build Deploy
2.Class
3.Core Library
4.Data Types
5.Database JDBC
6.Design
7.Development
8.File Input Output
9.Graphics Desktop
10.J2EE Enterprise
11.J2ME Wireless
12.JVM
13.Language
14.Library Product
15.Network
16.Security
17.SOA Web Services
18.Test
19.Web Development
20.XML
Java Articles » Test » HttpUnit 
HttpUnit is a framework based on JUnit, which allows the implementation of automated test scripts for Web applications. It is best suited for the implementation of automated functional tests, or acceptance tests. As the name suggests, it can be used for unit testing; however, typical Web layer components like JSP (JavaServer Pages) pages, servlets, and other template components do not lend themselves to unit testing. As for various MVC (Model-View Controller) framework-based components, these are better suited for testing with other testing frameworks. Struts actions can be unit tested with StrutsUnit, and WebWork 2 actions can be unit tested without a Web container, for example.

To be clear: the Dice web site is not written in Java. HttpUnit Black Box tests are compatible with any HTML/HTTP-based web site. Furthermore, the test is performed against a code base completely hidden from us. This is not to be taken lightly in scenarios of delegation and design by contract, where the tester and coder are not the same. The set is ready now for testing a real-world use case:

Part I concluded with a successful test of the application. To complete it, however, you still have to build the following functions: new contact, delete contacts, and edit contact. You also need to write the tests for those functions before implementing the application's full functionality. Part II completes the example, performing these tests and filling out the functionality of the phone list application.

Recorded Macros vs. Programmatic API The two primary methods for performing automated tests on Web applications are: [1] via recorded macros that can be played back and [2] via a programmatic API that parses HTTP responses. Recorded macros require frequent revisions and tend to be brittle. A programmatic API requires picking apart the HTML files received from the Web server and building object trees filled with HTML elements and textual content. This more flexible approach minimizes test maintenance in the most common cases and enables the testing of complicated functions in Web applications that return highly variable or complex HTML response pages. This is the approach HttpUnit takes.

ww__w__.___j___a_v_a__2___s_._c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.