RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Build a Java Web App Using HttpUnit and the Test-driven Methodology, Part I : Page 7

The HttpUnit client API complements JUnit functionality to provide thorough Web testing capability. This first article of a two-part series breaks down how HttpUnit delivers these features and walks you through a step-by-step setup of a test-driven environment.

Put Your Application to the Test
Now test the revised version of the code to see if the application passes. Perform the following steps:
  1. Stop Tomcat by typing ./shutdown.sh in the bin directory in the Tomcat distribution.
  2. Change your working directory to ~/projects/phonelist.
  3. Type ant undeploy.
  4. Type ant deploy.
  5. 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.

Wellie Chao has been active in the business of technology for many years, has been involved with software and hardware since 1984, and has been writing Web-based software in a variety of languages and on different platforms since 1994. .
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date