News
Features
Changes
Todo
Contributors

Downloads

Installation
Configuration
Using
Servlet Sample
FAQ

Architecture

Ant integration
Servlet Engines

API Reference

Support
Statistics


System Requirements

In order to use J2EEUnit for unit-testing you need to have the following software already installed on your system :

  • Java Virtual Machine A Java 1.2 or greater compatible virtual machine must be present. Note that all servlet engines require a JVM to run so if you are already using servlets you already have one installed.
  • Servlet Engine A Servlet 2.x compliant servlet engine for running your J2EUnit tests must be present. J2EEUnit works with any servlet engine. Sample Ant scripts are even provided for the most common ones (see the features list).
  • Ant Ant 1.3 or greater need to be installed only for building J2EEUnit and for automating J2EEUnit unit tests.

Libraries Dependencies

You may need to download several of the external libraries mentionned below to perform so tasks for running J2EEUnit tests or for building J2EEUnit :

  • JUnit The JUnit framework is needed both for building J2EEUnit and for running J2EEUnit tests.
  • Servlet API 2.2 and/or 2.3 You'll need the javax.servlet.* packages in order to build J2EEUnit only. You can download either the Sun API or the Jakarta reference implementation for Servlet API 2.2 and/or Servlet API 2.3. This is not needed for running J2EEUnit tests as these APIs are already provided by your servlet engine.
  • Stylebook version b3 for Xalan 2.0, Xalan 2.0, Xerces 1.3 This is needed for building the J2EEUnit documentation from the sources. Stylebook is downloadable from CVS, Xalan from here and Xerces from here. Note that you'll also need to use a JAXP 1.1 implementation (crimson.jar) as the XML parser for Ant (it should replace parser.jar for Ant 1.3 and before. Ant 1.4 is already JAXP 1.1 ready). JAXP 1.1 is needed for Xalan 2.0

Note In order to simply the gathering of these jars, I have packaged them in a zip file, that you can find in the download section :)


Installing J2EEUnit

The steps below show how to set up an environment for executing servlet unit tests. However, look at the J2EEUnit sample sources for an already set up environment that uses Ant to automate the running of unit tests.

Step 1 : Installation of J2EEUnit in your application to test

J2EEUnit works by calling a Redirector (either Servlet Redirector or JSP Redirector, both part of J2EEUnit) that you need to put where both the server-side code that you need to test and your test code are located. In other words, you need to do the following :

  1. Put the j2eeunit-<servlet API>-<version>.jar file in the WEB-INF/lib directory of the webapp that you are testing (If your servlet engine does not support web applications, just make sure that it is in the CLASSPATH of your servlet engine).
  2. Modify your web.xml file to include a mapping for the Redirector Servlet (If your servlet engine does not support web applications, you won't have any web.xml file. You'll need to edit your servlet engine configuration file and find out how to map a URL to a Servlet). This mapping contains :
    • the name of the Redirector Servlet class,
    • the URI that will be used to call the Redirector Servlet. This needs to match the URL specified in the j2eeunit.properties configuration file (see configuration),
    • configuration data that can be retrieved using the config implicit object.
  3. Modify your web.xml file to include a mapping for the Redirector JSP. This mapping contains :
    • the name of the Redirector JSP page,
    • the URI that will be used to call the Redirector JSP. This needs to match the URL specified in the j2eeunit.properties configuration file (see configuration).
    • configuration data that can be retrieved using the config implicit object.
  4. Copy the J2EEUnit Redirector JSP file called redirector.jsp in the document root of your test webapp.

Note The steps 3 and 4 above are only necessary if you wish to use the Redirector JSP for your tests and thus have access to the pageContext and out implicit objects (for testing custom tag libraries for example).

For example, if you have the following configuration :

  • Your webapp is called "mywebapp"
  • The URLs specified in your j2eeunit.properties are "http://localhost:8080/mywebapp/ServletRedirector" for the j2eeunit.servletRedirectorURL property and "http://localhost:8080/mywebapp/JspRedirector" for the j2eeunit.jspRedirectorURL property
  • The J2EEUnit Redirector JSP file redirector.jsp is put in a subdirectory named test/ in your webapp document root.

then your web.xml file should look like :

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>

    <servlet>
        <servlet-name>ServletRedirector</servlet-name>
        <servlet-class>j2eeunit.server.ServletTestRedirector</servlet-class>
        <init-param>
          <param-name>param1</param-name>
          <param-value>value1 used for testing</param-value>
        </init-param>
    </servlet>

    <servlet>
        <servlet-name>JspRedirector</servlet-name>
        <jsp-file>/test/redirector.jsp</jsp-file>
        <init-param>
          <param-name>param1</param-name>
          <param-value>value1 used for testing</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>ServletRedirector</servlet-name>
        <url-pattern>/ServletRedirector</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>JspRedirector</servlet-name>
        <url-pattern>/JspRedirector</url-pattern>
    </servlet-mapping>

</web-app>

Step 2 : Installation of your test code

You also need to put the test classes that you have written (see the using section) on the server side, along with the code to test. Put these classes in your WEB-INF/classes or WEB-INF/lib (If your servlet engine does not support web applications, just make sure that it is in the CLASSPATH of your servlet engine).


Step 3 : Client-side installation with JUnit

A J2EEUnit suite of tests is started using JUnit test runners (see the using section). You need to put the following files in your client-side CLASSPATH :

  • The JUnit jar file,
  • The J2EEUnit jar : j2eeunit-<servlet API>-<version>.jar,
  • Your test classes. This is needed because the beginXXX() and endXXX() methods are executed on the client side (see the using section for explanations on how to write tests using J2EEUnit and see the architecture section for an explanation on how J2EEUnit works)



Copyright © 2000-2001 Vincent Massol. All Rights Reserved.