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: Faukazahn Groshicage
Country: Malawi
Language: English (Spanish)
Genre: Art
Published (Last): 3 January 2013
Pages: 134
PDF File Size: 16.29 Mb
ePub File Size: 9.17 Mb
ISBN: 156-1-72538-577-9
Downloads: 25481
Price: Free* [*Free Regsitration Required]
Uploader: Vik

However these tests should be also executed automatically from time to time.

5.10 Submitting Form Data

Pay particular attention to the todo comments. Here’s an updated test scenario based on our TC architecture. For the automated test runs, the debug info will not be logged, but when I need to fix a specific problem, I can turn it on, and I will be able to see the actual HTML response received from the server in the log file. Searching for the Holy Grail of software development Based on the architectural requirements above, for each project I typically create a base Test Case class, which extends the jUnit TestCase class.

I use Eclipse 3. So all we need to do is to create a build. Based on the development method, this could be after a daily build, or during a testing period, but the best is to execute the full Test Suite or at least a subset many times a day, hourly for example, or after each commit in the Version Control system.

The specific Test Case implementations will contain one test method per Test Case scenario from the Test Case specification document. HttpUnit enables the programmers to write the test script to test web applications.

For this article, let’s assume that you have a set of things you want to test for your web application, organized into sets of Test Case scenarios. Specifying the authorization information. Each section of the tutorial will address a specific use of the system, and show how HttpUnit and ServletUnit can be used to write tests which verify that functionality.


Create the pool editor Task 2: This way the developers and the management can see the status of the application. Now we know how we can write and execute our tests in the IDE.

The user may change his bet until the pool is closed. The TCs are typically very fragile. For example, if we assert specific page titles, our tests will probably not run if the language is selectable in the httpunif, and we want to verify a different language deployment.

You might also consider putting your todo comments in your test cases, rather than in the code itself. This process reduces the likelihood that you will procrastinate and skip some of the tests. This code uses JUnit and ServletUnit httpunkt verify that a servlet is present at the specified address.

This application is fairly simple, and hardly robust, but contains more than enough interactions to allow us to explore development and testing with HttpUnit. Each method should be runnable successfully individually. This component is responsible acting on the response contents.

Testing Web Applications with HttpUnit (Don’t worry, it’s not boring!)

On the other hand, we should not over-architect a simple Test Httpuhit implementation. The class extends ConfigurableTestCase, and the login details are handled in the base class. The NewsletterServlet is nearly at its final form. Before we jump into the architecture and implementation details, it’s important to clarify exactly what the test scripts will need to prove about the httpunig application. These tools can capture the way the testers interact with the browser, and play it back in a configurable and sometimes programmable manner.

Unit Testing with HTTPUnit

OO design could reduce the effort of reworking common parts in the TCs, but from the perspective of a QA Engineer or tester, I’m sure that a simple, sequential script that interacts with a web site is easier to maintain and fix. I think the tktorial feedback is really tutoriwl – it gives a nice sense of accomplishment especially when writing Unit Tests for our own code.


Now that we’re aware of the requirements Use Case docs, and corresponding Test Case specificationswe understand the Framework’s basics, and we have hftpunit set of architectural guidelines, let’s get to work. This code should fail with a HttpNotFoundExceptionbecause we have not yet created the servlet class. During the development of a new system, the application lives on multiple servers, and the servers my run multiple versions.

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. Set parameters on the WebForm using its setParameter method.

Not to mention you can potentially save thousands of dollars Our application the target of the test should not be aware of any difference when serving up pages gttpunit a web browser or the test tool.

You then ask the form for a WebRequest object, passing in the name of one of the submit buttons. From these documents, we have to create an organized list of Test Cases. The Application Our application is an office sport betting pool. For the development of the Test Case implementations, I prefer to work in Eclipse.

When a specific test method in a TC implementation logs in, it has to specify which Login Role is required for that particular test scenario.

About Privacy Policy Contact. For my example I have created lib directory under learnhttpunit directory and copied the content of lib and jars directory into it.