Put Your Application to the Test
Now test the revised version of the code to see if the application passes. Perform the following steps:
- Stop Tomcat by typing ./shutdown.sh in the bin directory in the Tomcat distribution.
- Change your working directory to ~/projects/phonelist.
- Type ant undeploy.
- Type ant deploy.
- Start Tomcat by typing ./startup.sh in the bin directory in the Tomcat distribution.
You can try out the application at http://localhost:8080/phonelist/showList.do. The application should display the list of contacts successfully.
Go back to the ~/projects/phonelist directory and type "ant test". The showlist test should now pass because the URL it tests contains content and has four or more rows in a table with the title "Phone List".
You still have to build the following functions: delete contacts, new contact, and edit contact. You also need to write the tests for those functions. In fact, you should write the tests before implementing the functionality.
In this article, Part I of "Build a Java Web Application Using HttpUnit and Test-driven Methodology", you have learned the difference between programmatic API-driven testing and recorded macro-driven testing. You have also seen how HttpUnit complements the JUnit functionality to provide testing capability for Web applications, which ordinarily are difficult to test using only JUnit because they use HTTP calls rather than Java method calls. Finally, you have gone through a step-by-step setup of a test-driven environment and its accompanying functionality, as well as writing a test. In Part II, you will complete the example, performing more tests and filling out the functionality of the phone list application.