JUnitEE, a TestRunner inside the Container
Since Version 1.4 Cactus contains a new Servlet Test Runner that enables the same features than the JUnitEE was providing, but in an even easier way. Please check the TestRunner Howto tutorial.You can use the JUnitEE user interface to run your all your tests inside the Container. JUnitEE is a JUnit TestRunner that has been written as a servlet with the user interface in HTML format.
You cannot achieve all features of Cactus using JUnitEE as part of them depend on being executed on the client side. Executing JUnitEE from ANT commands will probably not be possible. Some benefits however of JUnitEE are:
- All class files are in one place: Install all your TestCase class-files only in your container classpath. Both TestCases derived from
junit.framework.TestCase
and fromorg.apache.cactus.JspTestCase
will be located in the same place and only once.- Run all TestCases in the container: You can mix both types of TestCases mentioned above in your test. All tests are executed inside the Container. You can use testcases derived from
junit.framework.TestCase
to test methods that do not require the http objects such as theHttpServletRequest
orHttpServletResponse
objects.Using JUnitEE is (relatively) simple. Assuming you have a container such as Weblogic, Tomcat or Orion functioning and you know how to configure Servlets and adding libraries to the Containers classpath and you are familiar with the basics of Cactus then the rest is easy.
- One good reason to use JUnitEE would be when you want to try Cactus quickly and are not concerned with automatic unit testing.
- Usage of standard JUnit testrunner (textui,swingui, ...) will not be possible if cactus is configured this way and thus the ant junit task cannot be used to automate the test.
How to install JUnitEE
Download the JUnitEE zip-file. Add a reference to
junitee.jar
to your Container classpath. Add also references tojunit.jar
,httpunit.jar
cactus.jar
andaspectjrt.jar
if you have not already done that.addjunitee.jar
in the same way as cactus.jar is added.Configure TestServlet in your Container. You may use the example servlet
org.infohazard.servlet.TestServlet
that comes with JUnitEE. Check JUnitEE documentation. TestServlet extendsjunit.htmlui.TestServletBase
that executesjunit.htmlui.TestRunner
i.e. the JUnitEE interface.
Executing the tests with JUnitEE
You request the tests from an html-page in your container. You can write the name of your testclasses according to the examples with JUnitEE as:
- a commandstring parameter such as "
/TestServlet?suite=fi.iki.kaila.MyTests&list=yes
"- as input using
<input type="text" name="suite" size=60 />
in a form element that requests TestServlet- as one or more option elements in a select element in the form-element
Tell JUnitEE to use Cactus redirector
The
cactus.properties
file must be located so that your container can find it e.g. in your containers classpath.