Test suite : Test Suite « JUnit « Java Tutorial






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

public class TestClassOne extends TestCase {

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

  public void testAddition() {
    assertEquals(4, 2 + 2);
  }

  public void testSubtraction() {
    assertEquals(0, 2 - 2);
  }
}

class TestClassTwo extends TestCase {
  public TestClassTwo(String method) {
    super(method);
  }

  public void testLongRunner() {
    assertEquals(2300, 0);
  }

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

class TestClassComposite extends TestCase {

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

  static public Test suite() {
    TestSuite suite = new TestSuite();
    // Grab everything:
    suite.addTestSuite(TestClassOne.class);
    // Use the suite method:
    suite.addTest(TestClassTwo.suite());
    return suite;
  }
}








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