Hi Matt,

> -----Original Message-----
> From: Matt Raible [mailto:[EMAIL PROTECTED]
> Sent: 08 January 2004 01:21
> To: Cactus Users List
> Subject: Login once using (FormAuthentication) for all tests in a
class
> 
> Quick and dirty question:
> 
> Is it possible to login once (using FormAuthentication) for a class,
> rather than adding a beginXXTestName befor every testXXTestName
method?
> 

hmm... There is a global begin(WebRequest) method. But it is called
before every test (it's the equivalent of setUp() but on the client
side). What we should do really is create the equivalent of JUnit
TestSetup but with methods names begin/end instead of SetUp/tearDown.
Patches much welcome :-)

> Longer explanation:
> 
> I have a number of tests in my ContactActionTest - this test extends
> CactusStrutsTestCase, which extends ServletTestCase - nothing is
really
> Struts specific in this scenario.
> 
> In order to simulate logging in, I've simply retrieved a user object
in
> by setUp() method and stuffed it into the session - this seems to
> simulate a login good enough.  However, today, I started logging down
> my Actions/Servlets with roles.  So now this doesn't work - do I have
> to have a beginXX before each testXX that logs the user in (with
> FormAuthentication)?

Thinking more about it, I'm not so sure that the solution is a method
that is called only once... Each test must set its own fixture. So you
should group test using the same fixture (i.e. user being logging in) in
the same TestCase class. Then simply use either begin() or even better
setUp() (it has direct access to the session) to log the user in before
*each* test.

Cactus is about unitary tests so each test must set its own fixture and
not depend on other tests or side effects.

Thanks
-Vincent


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to