Per-Suite Setup and Tear-Down : Test Suite « JUnit « Java Tutorial






import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class TestClassTwo extends TestCase {

  public TestClassTwo(String method) {
    super(method);
  }

  // This one takes a few hours...
  public void testLongRunner() {
    assertEquals(2300, 50);
  }

  public void testShortTest() {
    assertEquals(140, 5);
  }

  public void testAnotherShortTest() {
    assertEquals(586, 10);
  }

  public static Test suite() {
    TestSuite suite = new TestSuite();
    // Only include short tests
    suite.addTest(new TestClassTwo("testShortTest"));
    suite.addTest(new TestClassTwo("testAnotherShortTest"));

    TestSetup wrapper = new TestSetup(suite) {
      protected void setUp() {
        oneTimeSetUp();
      }

      protected void tearDown() {
        oneTimeTearDown();
      }
    };
    return wrapper;
  }

  public static void oneTimeSetUp() {
  }

  public static void oneTimeTearDown() {
  }
}








39.3.Test Suite
39.3.1.Test suite
39.3.2.Per-Suite Setup and Tear-Down
39.3.3.Define your own test case runner with reflection
39.3.4.Use the test suite method