Leandro Saad wrote:
>
> Hi all, I'm new to this list and I apologize if this has been already
> answered before.
No problem :)
> I installed the sample on my machine and I'm trying to figure out how it
> works : there is a ant task that get's executed and calls
> TestSampleServlet. TestSampleServlet.suite() says that every method
> beginnig with "test" should be executed.
> My question is , finally, what/how are those classes in unit/ used for
> ????
The sample package contains a sampleservlet to illustrate how to do
servlet unit testing. There is a TestSampleServlet class to show how to
test the servlet.
In the unit package are tests that can be used to test some of the
classes in cactus itself :) sort of a "self test".
JUnit:
junit uses introspection to find all methods that begin with "test", and
considers them as test methods to run. This is part of how the junit
testing framework actually works. So if you wanted to test something
outside of a servlet container you could use junit, e.g. perhaps for
testing a new collection that you write yourself.
See http://junit.org for the home of junit, and lots of good articles on
unit testing in general and junit.
If you want to see how to call the sampleservlet test without using ant,
then you should
- download and install junit
- then satisfy yourself that you can get simple unit tests running with
junit (i.e. those that run within junit entirely).
- then set up your servlet engine to "see" the cactus jar file, and the
servletredirector - see the configuration section on the website for how
to do this. basically it means editing web.xml to add in the cactus
servlet and making sure the cactus jar file is picked up. If you put the
servlet on /test/ServletRedirector, then you should be able to try and
call the servlet to see that the server side part of cactus is set up.
so if you are running on localhost then call
http://localhost:8080/test/ServletRedirector. You will receive a
ServletException, which should have the following message:
"Missing parameter [ServletTestRedirector_Service] in HTTP request"
This shows your server side is setup.
- then you need to setup the client part of cactus - this is the part
that calls the ServletRedirector to run your tests. You need to make
sure that the cactus.properties file is in the classpath to be seen by
junit (this is how it knows what URL to call to run tests). then you
need to make sure the cactus jar and junit jars are in the CLASSPATH.
- you're now ready to begin!
- set the server running.
- set junit running
- run the "TestSampleServlet" test using junit
There is more detail on the website if you get stuck.
Lastly,
It is important to remember that you are configuring 2 JVM's - one for
the server, the other for the client part of the tests.
Jari
--
Jari Worsley
Senior Programmer
Hyperlink Interactive Ltd