ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "P. Fleury" <>
Subject Re: JUnit: setUp() method called multiple times ?
Date Thu, 03 Oct 2002 04:40:14 GMT
Hum, sorry, when I meant "test" I really wanted to say "before every 
test* method call, setUp() is called". That means, in a single junit 
test (as specified by the junit task, meaning one *Test class file), the 
setUp metho gets called multiple times.
If I scatter a few System.err.println() around as first things in the 
methods, I get this (the setUp counter is implemented as a static variable)

call to setUp (#1th call...)
call to testMultipleContentMakagerLink()
call to setUp (#2th call...)
call to setUp (#3th call...)
call to setUp (#4th call...)
call to setUp (#5th call...)
call to setUp (#6th call...)

Even more interestingly, the actual testMethods are not called at all. 
In the first test, it uses some fairly obvious JNI stuff, could I have 
messed something up there and get it to have this behavior ?


Dushyant Shrivastava wrote:

>Yes this behaviour is correct! setUp() and tearDown() methods are designed to be esecuted
before and after each test in your test case.What you could do is have just 1 setup method
higher up in your test case. You can do this by providing a wrapper class to override the
setUp method of TestSetup class and this enables the setUp of the Wrapper class to be run
just once before the tests.Acts like an initialisation point. You can do the same for tearDown
as well
>Something like this:
> class Wrapper extends TestSetup{
>  public Wrapper(junit.framework.Test p0){
>    super(p0);
>  }
>  public void setUp(){
>    oneTimeSetUp();
>  }
>  public void tearDown(){
>   finalTearDown();
>  }
> }
>and then define your oneTimeSetUp method ->
>public static void oneTimeSetUp()
>  {
>  }
>hope this helps!!

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message