StrutsTest Setup On Eclipse

This is using the Eclipse IDE and Tomcat. Download strutsTest from http://sourceforge.net/
project/showfiles.php?group_id=39190 (all one line).

Make sure the following jars are in WEB-INF/lib (the classpath)

  • junit.jar servlet.jar 
  • struts.jar 
  • commons-digester.jar 
  • commons-collections.jar 
  • commons-logging.jar 
  • commons-beanutils.jar 
  • jaxp.jar 
  • crimson.jar 
  • strutstest.jar 
  • cactus.jar 
  • commons-httpclient.jar 
  • aspect.jrt.jar 

Cactus.properties

There should be a cactus.properties file in the jar. Place it directly under "src" and edit for configuration.

Example:

cactus.contextURL = http://localhost:8080 cactus.servletRedirectorName = ServletRedirector cactus.enableLogging=true

Cactus-report.xsl (Stylesheet for browser display) 

Download cactus-report.xsl from http://jakarta.apache.org/cactus/misc/cactus-report.xsl and put in the project's root (i.e. under Webroot in the Eclipse IDE).

Web.xml

If using cactus, add the following to web.xml, before action stuff.
<!-- Cactus servlet Redirector Configuration -->
<servlet>
<servlet-name>ServletRedirector</servlet-name>
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
</servlet>

<servlet>
<servlet-name>ServletTestRunner</servlet-name>  <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>
</servlet>
and under mapping area ...
    <!-- Cactus Servlet Redirector URL mapping -->
<servlet-mapping>
<servlet-name>ServletRedirector</servlet-name>
<url-pattern>/ServletRedirector</url-pattern>
</servlet-mapping>
 <servlet-mapping>
 <servlet-name>ServletTestRunner</servlet-name>
 <url-pattern>/ServletTestRunner</url-pattern>
 </servlet-mapping>

Running StrutsTest

See examples in the downloaded file for ready-made stuff.


Basic Steps to Create Struts Tests

Create separate test package. Extend either MockStrutsTestCase or CactusStrutsTestCase. 

Can run from Eclipse or from browser using:  http://localhost:8080/ServletTestRunner?
suite=your.project.location/your.test.action.class.name (all one line)

For an html-formatted report, add "&xsl=cactus-report.xsl" to the end of the uri.

Suggestions? Comments? Use our contact page.
Back to programming examples and notes.