Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

StrutsTestCase: Drilled-down Testing for Struts-based Java Apps : Page 2

This article demonstrates both mock testing and in-container testing of Web-based applications built with the Struts Model-View-Controller framework. StrutsTestCase, a small testing library that builds on top of the JUnit testing framework, allows you to perform both testing methodologies on Struts applications.


advertisement
Set Up the Environment
Make sure you have the following packages installed prior to setting up your testing environment:
  • Ant 1.6.1. Ant is the build tool you will use to build the Web application. It is available at ant.apache.org.
  • Tomcat 4.1.29. Tomcat is the servlet container in which your Web application will run. It is available at jakarta.apache.org/tomcat.
  • Struts 1.1. Struts is the MVC framework on which you'll build your Web application. It is available at jakarta.apache.org/struts.
  • Cactus 1.5. Cactus is the in-container testing framework on which StrutsTestCase is built. It is available from jakarta.apache.org/cactus. Once you get to the download page, get the file at the link labeled "1.5 zip for J2EE API 1.3". The Cactus distribution includes JUnit 3.8.1, so you do not have to download and install JUnit 3.8.1 separately.
  • Xerces 2.6.1. Xerces is a SAX-compliant and JAXP-compliant XML parser that StrutsTestCase uses to parse struts-config.xml and tiles-defs.xml. The main site is at xml.apache.org/xerces2-j/index. You can download it at www.apache.org/dist/xml/xerces-j. Download the file called "Xerces-J-bin.2.6.1.tar.gz".

To keep files and directories organized, you should unpack each of the above packages to ~/packages (creating the ~/packages directory, if necessary) so that each one is a subdirectory of ~/packages. The remaining instructions in this article assume that you unpack files to ~/packages. If you choose a different location, make the corresponding changes.

Get the StrutsTestCase library from sourceforge.net. The project home page is at strutstestcase.sourceforge.net, in case you want to access other StrutsTestCase resources. The latest version of StrutsTestCase as of the writing of this article is StrutsTestCase 2.1, which complies with the Java Servlet 2.3 API and supports the following Java tools:

  • Struts 1.1
  • Cactus 1.5
  • JUnit 3.8.1



Once you have the strutstest210-1.1_2.3.zip file, unzip it. Unzipping it to ~/packages will create a directory called ~/packages/strutstest. If you use a different directory, make sure to substitute any occurrence of ~/packages/strutstest in the remainder of this article with the actual location of strutstest.

Download the phonelist-strutstestcase.tgz file from the "Download the Code" section in the left margin. It contains the same phone list application from my previous HttpUnit articles, "Build a Java Web App Using HttpUnit and the Test-driven Methodology", Parts I and II. (Read these articles for a step-by-step guide to the phone list application's development.) Unpack the phonelist-strutstestcase.tgz file in the ~/projects directory (create the ~/projects directory, if necessary). This should create a directory called phonelist-strutstestcase.

You now need to tailor the build.xml file in phonelist-strutstestcase, so that the directories point to the proper locations. Open up build.xml in your text editor and replace the values of the tomcat.install.dir, struts.install.dir, cactus.install.dir, xerces.install.dir, and strutstestcase.install.dir properties with the correct directory locations of Tomcat, Struts, Cactus, Xerces, and StrutsTestCase, respectively.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap