Test Skeleton : TestCase « JUnit « Java Tutorial






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

public class TestSkeleton extends TestCase {

  /**
   * Per-method test set up
   */
  public void setUp() {
  }

  /**
   * Per-method test tear down
   */
  public void tearDown() {
  }

  /**
   * Add tests here: public void testName() ...
   */

  public TestSkeleton(String name) {
    super(name);
  }

  /**
   * Default suite method
   */
  public static Test suite() {
    return new TestSuite(TestSkeleton.class);
  }

  /**
   * Note -- "main" will only be run when invoked individually from the command
   * line (not via Ant's JUnit Task, etc.)
   */

  public static void main(String[] args) {
    TestSuite suite = new TestSuite();

    if (args.length != 0) {
      // Run specific tests as indicated from the
      // command line
      for (int i = 0; i < args.length; i++) {
        suite.addTest(new TestSkeleton(args[i]));
      }
    } else {
      // Dynamically discover all of them, or use
      // user-defined suite
      suite.addTest(TestSkeleton.suite());
    }
    junit.textui.TestRunner.run(suite);
  }
}








39.2.TestCase
39.2.1.extends TestCase
39.2.2.Use assertEquals in a test method
39.2.3.JUnit Test Composition
39.2.4.Per-Test Setup and Tear-Down
39.2.5.Test Skeleton
39.2.6.Test your stack structure
39.2.7.Test algorithm
39.2.8.Init class being tested in test case method