HttpUnit is an open source test framework for web applications which can provide browser specific behaviour like sending request to the We are using Spring sts , JDK 8, HttpUnit JUnit Tutorial for Unit Testing. 4. However if you’re a programmer who just got the job to create functional or unit tests, you’ll find HttpUnit a much more enjoyable and programmer-friendly toolkit. HttpUnit allows us to test navigating through our JSPs by clicking links and buttons and filling out forms. In this tutorial, we will explain.

Author: Dijin Akinogis
Country: Brazil
Language: English (Spanish)
Genre: Marketing
Published (Last): 15 May 2005
Pages: 34
PDF File Size: 8.99 Mb
ePub File Size: 14.12 Mb
ISBN: 325-9-58375-372-4
Downloads: 10146
Price: Free* [*Free Regsitration Required]
Uploader: Yoshura

Tuyorial you’re an experienced OO developer, there’ll be great temptation to create class hierarchies and create common classes for these things. Finally, Example shows the revised JSP. So concentrate on verifying the functionality of the web application, rather than checking everything possible on the page. Now that we’re aware of the requirements Use Case docs, and corresponding Test Case specificationswe understand the Framework’s basics, and we have a tutorjal of architectural guidelines, let’s get to work.

Typically Web Applications should not allow input which can cause a system-wide failure, but perhaps the reason of the automated Test Case is to highlight such an issue in the application.

In some projects performance requirements must be fulfilled, so the QA engineers perform load tests to verify and document how the application performs under various conditions. This code uses JUnit and ServletUnit to verify that a servlet is present at the specified address. Don’t assume a specific execution order for your Test classes, or the test methods within the classes. Potentially each component can pass the unit tests alone – however the developers need to make sure that they work together as expected, as part of a subsystem, and as part of the whole application, hence integration tests must be performed.


I typically have a log. After you implement each test, it should fail until you then add the implementation.

Since we are working with servlets, we can bypass the web server and use the servletunit package to run our tests. The class extends ConfigurableTestCase, and the login details are handled in the base class.

10x More Productive Blog!

The runner will display the list of recognized test methods, and the result of the execution. I think it’s important not to treat the TC code as important systems code – it must be easy to maintain it, and it should not require a J2EE Architect to understand it and work with it.

In a typical enterprise application, there are many areas requiring testing. You then ask the form for a WebRequest object, passing in the name of one of the submit buttons. That is, first you are encouraged to write and execute a test for the next piece of functionality to be added, verify that the test fails demonstrating that the functionality is not in placeand then implement the functionality and verify that the test now passes.

Set parameters on the WebForm using its setParameter method.

When everything was OK tutorjal the test run, it will give us a nice green line. This tool is based on Unit which is also Java based free testing tool. OK, now we know the boring stuff, let’s download some cool toys!


Obviously it’s a bad idea to keep the server name in the Java implementation – for each new server we’d need to recompile our sources. It will take you through the incremental development of a simple servlet-based web application using a test-first approach.

Traceability is very important for our Test Cases. I always create a LoginMode enum, which contains the available roles. You want to write a test that submits your HTML forms and verifies the forms functionality.

HttpUnit Tutorial

Create a Httupnit file file example1. The test-first process can continue until all of the functionality is implemented. Each Test Case implementation extends this class.

It could be argued that externalizing the URLs to property files for example could potentially reduce the effort htgpunit maintain the Test Cases, but it would be harder for a tester to review and update a Test Script. That’s exactly what HttpUnit provides: The specific Test Case implementations will contain one test hftpunit per Test Case scenario from the Test Case specification document.

It also pre-fills the value of the name field if necessary. These “viral” tests can be excluded from the batch test run, and they can be run separately, restoring the initial database state after running them.