ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dushyant Shrivastava" <dus...@yambay.com>
Subject RE: JUnit: setUp() method called multiple times ?
Date Thu, 03 Oct 2002 04:27:06 GMT
Hi,
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!!

Dushy
-----Original Message-----
From: P. Fleury [mailto:fleury@users.sourceforge.net]
Sent: Thursday, October 03, 2002 12:17 PM
To: Ant Users List
Subject: JUnit: setUp() method called multiple times ?


Hello,

I have a single test class which has setUp() method. When I run it 
through the junit task, in batch, the setUp method gets called once for 
each test. Is that the normal behavior ? My problem is that multiple 
runs of setUp make things fail...

Anybody having similar issues?  Ant 1.5, Sun's JDK 1.4.0_01, Linux 
RH7.3, JUnit 3.7

--Pascal

###Here is the stub of my class (partially generated by NetBeans):

public class JNIContentManagerTest extends TestCase {
   
    public JNIContentManagerTest(java.lang.String testName) {
        super(testName);
    }
   
    public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(suite());
    }
   
    public static Test suite() {
        TestSuite suite = new TestSuite(JNIContentManagerTest.class);
        return suite;
    }
   
    private MockContentManagerLink cml = null;
    private JNIContentManager    jnicm = null;
   
    private static int count_setups = 0;
   
    protected void setUp()  {
        count_setups++;
        System.err.println("setup #"+count_setups+" called.");
        // do initialization
    }
   
    public void testMultipleContentManagerLink() {
        System.out.println("testMultipleContentManagerLink");             
    }
   
   
    /** Test of createNewReference method, of class 
com.sony.vesta.jnicm.JNIContentManager. */
    public void testCreateNewReference() {
        System.out.println("testCreateNewReference");      
    }
   
    /** Test of getFilename method, of class 
com.sony.vesta.jnicm.JNIContentManager. */
    public void testGetFilename() {
        System.out.println("testGetFilename");
    }
      
}

### Ant the JUnit task:
      <junit fork="true" dir="${lib.dir}">
         <formatter extension=".xml" type="xml" usefile="true"/>
         <classpath refid="class.path"/>
            <sysproperty key="java.library.path" 
value="${ld.library.path}:${env.LD_LIBRARY_PATH}"/>
            <jvmarg value="-Xcheck:jni"/>
            <batchtest fork="true" todir="${testresults.dir}">
                <fileset dir="${class.dir}">
                    <include name="**/*Test.class"/>
                </fileset>
            </batchtest>
      </junit>




--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message