You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Vincent Massol <vm...@pivolis.com> on 2004/08/24 08:01:14 UTC

RE: Getting started with cactus

Hi Lee,

> -----Original Message-----
> From: Lee Chalupa [mailto:lchalupa@seelink.org]
> Sent: mardi 24 août 2004 04:05
> To: Vincent Massol
> Subject: Getting started with cactus
> 
> 
> Vincent:
> 
> This is Lee. We talked about me contributing some time to try to improve
> the
> documentation for Cactus.
> 
> I have a few basic questions to start with. I'm starting with running
> cactus
> tests with a browser to test a servlet.  My question has more to do with
> the
> functionality of cactus.  Let me explain what I want to do using an
> example of
> a servlet.
> 
> The servlet is called SeeReportServlet. A html form will submit three
> parameters
> to the doGet method of this servlet: LOGLEVEL, FORMAT, and REPORT.
> LOGLEVEL is a required field, FORMAT must have a value of "PDF" or "DHTML"
> and
> REPORT must be an existing class that can be found (this is the report
> class
> that will be run to generate the report).
> 
> I guess I'm confused here because the container (Tomcat) actually calls
> the
> doGet method of SeeReportServlet where as in other java applications
> (swing
> client), as part of a test fixture I might create an instance of class and
> then
> call it's method and test the outcomes. I'm not sure what the code should
> be
> doing in my test class.
> 
> I understand that in the begin method I can populate these three
> parameters with
> test values, I'm not sure what the test method would actually contain.
> 
> Is this making any sense?

The beginXXX method will indeed contain the parameters (executed on the
client side). The testXXX method (executed on the server side) will contain
whatever you wish to assert there.

I believe the confusion comes from the fact that you consider Cactus a
functional testing framework whereas it is not. It is a unit testing
framework. For functional tests you should use HttpUnit, HtmlUnit or any of
these functional testing frameworks.

Imagin your servlet is written like this:

public class MyServlet...
{
   public void doGet(...)
   {
      callMethod1(...);
      callMethod2(...);
      callMethod3(...);
   }

   public ... callMethod1(...)
   {
      ...
   }

   public ... callMethod2(...)
   {
      ...
   }

   public ... callMethod3(...)
   {
      ...
   }
}

Cactus will allow you to unit test callMethodX() methods separately (exactly
in the same way you use a JUnit test).

For examples of tests please see
http://jakarta.apache.org/cactus/writing/howto_testcase.html, step 5.

You can also check the sample servlet application which is bundled in the
Cactus distribution.

-Vincent

PS: Please always use the Cactus mailing list and not my direct email.