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: Tazahn Vugal
Country: Morocco
Language: English (Spanish)
Genre: Finance
Published (Last): 19 September 2008
Pages: 29
PDF File Size: 2.67 Mb
ePub File Size: 18.7 Mb
ISBN: 321-8-96817-826-2
Downloads: 95074
Price: Free* [*Free Regsitration Required]
Uploader: Tedal

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. We will also need the Ant build tool to run the tests and generate reports automatically. This tutorial shows you how to use HttpUnit to test your web applications.

Welcome to the example 1.

Of course it should be also possible to log in with a specific user, for example to verify the “Register User” Use Case It’s also useful to include the version number of those documents.

First httpunif all, we need an installed Java 2 SDK, to be able to compile and execute our tests. This way the developers and the management can see the status of the application. It’s better to select a Form to submit based on its ID: Invoking the servlet via its URL. All of this is shown in Example In order to maintain the conversation state Cookies, Session, Windows with the web server WebConversation class it used.


Unit Testing with HTTPUnit

Starting from the simplest components, classes, the developers or specialized test developers will need to program unit tests to ensure that the smallest units of the application behave correctly. This step would allow you to write standalone tests against the ttorial logic without invoking the servlet. If the field is missing, the form should be redisplayed with an error message.

Each method typically logs in with a httlunit Role, and then executes the interaction tuorial the web application. When the form is redisplayed, the name field should be pre-filled with the previously entered value. Similarly, there’s little point checking an item on the page based on its position within a table layout; table based designs change frequently, so we should strive to identify elements based on their IDs.

To compile and test the example go to learnhttpunit directory and execute addtopath. Home Programming Java extreme programming. Example shows the updated servlet. It could be argued that externalizing the URLs to property files for example could potentially reduce the effort to maintain the Test Cases, but it would be harder for a tester to review and update a Test Script. When everything was OK during the test run, it will give us a nice green line. So concentrate on verifying the functionality of the web application, rather than checking everything possible on the page.

HttpUnit Tutorial – create pool editor – step 1

Traceability is very important for our Test Cases. Creating the ServletRunner class which represents access to a Servlet application. You fill in form field values using the setParameter method on a WebForm instance. As is typical in a web application, the validation logic is contained within the servlet, rather than the Tutodial. Configurable Test Case implementations.


For the development of the Test Case implementations, I prefer to work in Ttorial. To run this code, you will also need the web.

However these tests should be also executed futorial from time to time. Check out the detailed API guide for the rest of the classes and methods, this is just a brief overview for the classes I use most frequently. This application is fairly simple, and hardly robust, but contains more than enough interactions to allow us to explore development and testing with HttpUnit. This code uses JUnit and ServletUnit to verify that a servlet is present at the specified address.

This process reduces the likelihood that you will procrastinate and skip some of the tests. The framework then returns a WebResponsecontaining the returned page and attributes from the server. It will take you through the incremental development of a simple servlet-based web application using a test-first approach.

ServletUnit does not maintain a database of users, no any username httlunit accepted, and the password is interpreted as a comma-separated list of role names associated with the user. Even better, you might want to refactor the validation logic into a helper class rather than the servlet itself.

Invoking the Pool Editor

Time to Download Stuff! Don’t assume a specific execution order for your Test classes, or the test methods within the classes. When a development project is nearing completion of a specific milestone, acceptance tests can be performed to verify that the application fulfilled the requirements.