Source of ExtensionTest.java


  1: package junit.tests.extensions;

  3: import junit.framework.*;
  4: import junit.extensions.*;
  5: import junit.tests.WasRun;

  7: /**
  8:  * A test case testing the extensions to the testing framework.
  9:  *
 10:  */
 11: public class ExtensionTest extends TestCase {
 12:         static class TornDown extends TestSetup { 
 13:                 boolean fTornDown= false;
 14:                 
 15:                 TornDown(Test test) {
 16:                         super(test);
 17:                 }
 18:                 protected void tearDown() {
 19:                         fTornDown= true;
 20:                 }
 21:         }
 22:         public void testRunningErrorInTestSetup() {
 23:                 TestCase test= new TestCase("failure") {
 24:                         public void runTest() {
 25:                                 fail();
 26:                         }
 27:                 };

 29:                 TestSetup wrapper= new TestSetup(test);

 31:                 TestResult result= new TestResult();
 32:                 wrapper.run(result);
 33:                 assertTrue(!result.wasSuccessful());
 34:         }
 35:         public void testRunningErrorsInTestSetup() {
 36:                 TestCase failure= new TestCase("failure") {
 37:                         public void runTest() {
 38:                                 fail();
 39:                         }
 40:                 };

 42:                 TestCase error= new TestCase("error") {
 43:                         public void runTest() {
 44:                                 throw new Error();
 45:                         }
 46:                 };

 48:                 TestSuite suite= new TestSuite();
 49:                 suite.addTest(failure);
 50:                 suite.addTest(error);
 51:                 
 52:                 TestSetup wrapper= new TestSetup(suite);

 54:                 TestResult result= new TestResult();
 55:                 wrapper.run(result);

 57:                 assertEquals(1, result.failureCount());
 58:                 assertEquals(1, result.errorCount());
 59:         }
 60:         public void testSetupErrorDontTearDown() {
 61:                 WasRun test= new WasRun();

 63:                 TornDown wrapper= new TornDown(test) {
 64:                         public void setUp() {
 65:                                 fail();
 66:                         }
 67:                 };

 69:                 TestResult result= new TestResult();
 70:                 wrapper.run(result);

 72:                 assertTrue(!wrapper.fTornDown);
 73:         }
 74:         public void testSetupErrorInTestSetup() {
 75:                 WasRun test= new WasRun();

 77:                 TestSetup wrapper= new TestSetup(test) {
 78:                         public void setUp() {
 79:                                 fail();
 80:                         }
 81:                 };

 83:                 TestResult result= new TestResult();
 84:                 wrapper.run(result);

 86:                 assertTrue(!test.fWasRun);
 87:                 assertTrue(!result.wasSuccessful());
 88:         }
 89: }