ant-user mailing list archives

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

  public void setUp(){

  public void tearDown(){

and then define your oneTimeSetUp method ->

public static void oneTimeSetUp()

hope this helps!!

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


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


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

public class JNIContentManagerTest extends TestCase {
    public JNIContentManagerTest(java.lang.String testName) {
    public static void main(java.lang.String[] args) {;
    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()  {
        System.err.println("setup #"+count_setups+" called.");
        // do initialization
    public void testMultipleContentManagerLink() {
    /** Test of createNewReference method, of class */
    public void testCreateNewReference() {
    /** Test of getFilename method, of class */
    public void 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" 
            <jvmarg value="-Xcheck:jni"/>
            <batchtest fork="true" todir="${testresults.dir}">
                <fileset dir="${class.dir}">
                    <include name="**/*Test.class"/>

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

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

View raw message