I have now tried your testcase examples.
Maybe I have not been explaining it well enough.
The oneTimeSetup worked perfectly, it was the oneTimeTearDown which didn't work.
The example below should show what I mean.
- Code: Select all
import junit.extensions.UITestCaseSWT;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* A test to verify that one time tear down is getting called as expected.
* <p>
* Copyright (c) 2007, Instantiations, Inc.<br>
* All Rights Reserved
*
* @author Phil Quitslund
*
*/
public class OneTimeTearDownTest extends TestCase {
public static class TestWTearDown extends UITestCaseSWT {
public TestWTearDown() {
}
static int counter;
@Override
protected void oneTimeSetup() throws Exception {
super.oneTimeSetup();
counter = 10;
}
public void testCounter() {
assertEquals(10, counter);
counter++;
}
@Override
protected void oneTimeTearDown() throws Exception {
super.oneTimeTearDown();
assertEquals(11, counter);
counter = 5;
}
}
public static class TestWOTearDown extends UITestCaseSWT {
public TestWOTearDown() {
}
public void testCounter() {
assertEquals(5, TestWTearDown.counter);
}
}
public static TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(TestWTearDown.class);
suite.addTestSuite(TestWOTearDown.class);
return suite;
}
}
The second testcase fails because counter is 11, but should be 5 due to the oneTimeTearDown call.