Tutorials : StrutsTestCase: The Tool for Struts Unit testing :

StrutsTestCase versions

The current release of STC is 2.0. Note, that there is a version for servlet specifications 2.2 and 2.3, and you should pick the version that corresponds to the level supported by your web server. The war-file mentioned above includes the 2.3- version. The STC download contains, first of all, an STC jar- file which you must place in your classpath. The rest of the download is documentation (including JavaDoc) and examples.

Here's a Windows bat-file, setcp.bat,  which you can use for setting up the proper classpath for compiling and running an STC program testing the DVD Library application. The setup assumes Tomcat, but it should be possible to use it with any servlet container, after making minor modifications:

Listing 2: setcp.bat - a Windows bat-file that sets the correct classpath
@echo off
set TOMCATROOT=d:\apache\jakarta-tomcat-4.1.12\
set APPDIR=%TOMCATROOT%\webapps\dvdlib
set LIBDIR=%APPDIR%\web-inf\lib\

set CP=.
set CP=%CP%;%TOMCATROOT%common\lib\servlet.jar
set CP=%CP%;%APPDIR%
set CP=%CP%;%LIBDIR%struts.jar
set CP=%CP%;%LIBDIR%strutstest-2.0.0.jar
set CP=%CP%;%LIBDIR%junit.jar

rem Remove the 'rem' if jdk1.4 is NOT used
rem set CP=%CP%;%TOMCATROOT%common\lib\xerces.jar

rem JDOM is used by the DVDManager class
set CP=%CP%;%TOMCATROOT%common\lib\jdom.jar

set CLASSPATH=%CP%
set CP=

To use it you must:

  • set TOMCATROOT to the directory where you've installed Tomcat.
  • set APPDIR to the web server directory where the dvdlib web application is placed.
    Important: This directory must be in the classpath in order for STC to find struts- config.xml.
  • set LIBDIR to the dvdlib directory containing jar-files.
    As you can see it's used to include jar-files for STC, JUnit,and Struts
  • you'll also need a servlet jar-file, a JDOM jar-file, and if you don't use jdk 1.4 (which I strongly recommend you do), an XML parser like Xerces. I've placed these files in Tomcat's common/lib directory. 

To simplify things I place my STC test programs in the same directory as the dvdlib application (WEB- INF/classes/hansen/playground). If the setcp bat-file is placed in the classes directory you can compile and run an STC program with this recipe (on Windows):

Table 1: The recipe for compiling and running STC programs
  • open a DOS-window
  • go to the classes directory
  • issue the command "setcp" 
  • issue the command "set" to verify that setcp worked as it should
  • to compile enter "javac hansen\playground\<name_of_testprogram>.java
  • to run the compiled program enter "java hansen.playground.<name_of_testprogram>

We're now ready to run our first STC program, but first a quick recap. STC tests your Struts actions, and the place where they're defined are in the struts-config file.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.