Java Reference
In-Depth Information
14.9
Executing Cactus tests from the browser
We know several different ways to execute JU nit tests. We looked at executions
through JU nit's own test runner, with the Ant and Maven test runners, and also
through Jetty. As you already know, Cactus tests are also JU nit tests, so the question,
“What is the analogue of the JU nit text test runner for Cactus?” seems valid and rea-
sonable. JU nit's test runner communicates directly with the JVM in which the execu-
tion takes place and gets the result from there. Cactus tests are executed in the server
JVM , so we need to find a way to communicate with the server (tell it to invoke the
tests and get the results).
The easiest way to communicate with the server is via a browser. In order to do this,
we need to take care of a couple of things.
First, we need to declare the ServletTestRunner servlet in the application's
web.xml. The declaration is shown in listing 14.22.
Listing 14.22 ServletTestRunner declaration
[...]
<servlet>
<servlet-name>ServletTestRunner</servlet-name>
<servlet-class>
org.apache.cactus.server.runner.ServletTestRunner
</servlet-class>
</servlet>
[...]
<servlet-mapping>
<servlet-name>ServletTestRunner</servlet-name>
<url-pattern>/ServletTestRunner</url-pattern>
</servlet-mapping>
[...]
Once it's declared, we're going to use this servlet in our URL in the browser to tell
the server to invoke the tests. We need to call the server with the following request
in the browser:
http://server:port/mywebapp/ServletTestRunner?suite=mytestcase
Here you need to replace server , port , mywebapp , and mytestcase with the correct
values of your server address, port number, context, and the fully qualified name (that
is, with packages) of your TestCase class containing a suite() method.
After executing the given URL in the browser, the server should respond with the
result shown in figure 14.4.
If you see a blank page, click the View Source option of your browser. It means
your browser doesn't know how to display XML data. Okay, that's nice, but what if
you want HTML instead of XML ? Don't worry; there's a solution. Grab the XSLT
stylesheet that comes with Cactus (cactus-report.xsl, based on the stylesheet used by
 
 
 
 
 
Search WWH ::




Custom Search