This tutorial should help you to learn to use HttpUnit to develop and test your web sites. It will take you through the incremental development of a simple servlet-based web application using a test-first approach. 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 place), and then implement the functionality and verify that the test now passes.
The initial tasks will use the
class, thus bypassing the need for a web browser or servlet
engine. Later tasks will require a web browser and a servlet engine, and use
Our application is an office sport betting pool. An administrator is designated to manage the pool, which includes opening and closing the betting. Entrants select the winner in each of the up to 10 games defined by the administrator and also guess the total score in one of those games, as designated by the administrator. The winner of the pool is the one who got the most winners correct, with any ties going to the person whose predicted total score in the tie-breaker game was closest to the actual final score.
We will identify the following uses of the system:
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 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. You should begin each section by copying the initial directory, which includes an ant build script and some classes that you will need to complete it. Running the ant script will compile the code and run the tests. If you are not using ant, compile and run tutorial.TutorialTestSuite. After you implement each test, it should fail until you then add the implementation.