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 Sean Zhang <se...@verizon.com> on 2002/01/17 23:08:34 UTC

Class variable in test case class loses its value

Hi,

I noticed that if I declare a class variable (a counter) in the test case
class and wants to access its value from the server side (for example, to
see how many tests are in the test case), its value is reinitialized for
each testXXX I have.  Is it because for each testXXX() method I have, there
is a round trip from client --> server --> client and the test case class is
instantiated for each testXXX() method?

Thanks,

Sean

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Class variable in test case class loses its value

Posted by Vincent Massol <vm...@octo.com>.
It is a feature of JUnit. In order for each test to be ran independently
of another, JUnit uses a custom classloader. So, for each test case, the
test case class is reloaded.

You have 2 options :
- do not use static variables (recommended way)
- there is a JUnit flag to turn of the classloading stuff (see the JUnit
doc as I don't know the flag).

-Vincent

> -----Original Message-----
> From: Sean Zhang [mailto:sean.zhang@verizon.com]
> Sent: 17 January 2002 22:09
> To: Cactus Users List
> Subject: Class variable in test case class loses its value
> 
> Hi,
> 
> I noticed that if I declare a class variable (a counter) in the test
case
> class and wants to access its value from the server side (for example,
to
> see how many tests are in the test case), its value is reinitialized
for
> each testXXX I have.  Is it because for each testXXX() method I have,
> there
> is a round trip from client --> server --> client and the test case
class
> is
> instantiated for each testXXX() method?
> 
> Thanks,
> 
> Sean
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>
> 




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>