jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@pivolis.com>
Subject RE: Login once using (FormAuthentication) for all tests in a class
Date Thu, 08 Jan 2004 08:55:07 GMT
Hi Matt,

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

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
> Struts specific in this scenario.
> In order to simulate logging in, I've simply retrieved a user object
> 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.


View raw message