1 package junit.tests; 2 3 import junit.framework.*; 4 import junit.extensions.*; 5 6 10 public class ExtensionTest extends TestCase { 11 static class TornDown extends TestSetup { 12 boolean fTornDown= false; 13 14 TornDown(Test test) { 15 super(test); 16 } 17 protected void tearDown() { 18 fTornDown= true; 19 } 20 } 21 public ExtensionTest(String name) { 22 super(name); 23 } 24 public void testRunningErrorInTestSetup() { 25 TestCase test= new TestCase("failure") { 26 public void runTest() { 27 fail(); 28 } 29 }; 30 31 TestSetup wrapper= new TestSetup(test); 32 33 TestResult result= new TestResult(); 34 wrapper.run(result); 35 assertTrue(!result.wasSuccessful()); 36 } 37 public void testRunningErrorsInTestSetup() { 38 TestCase failure= new TestCase("failure") { 39 public void runTest() { 40 fail(); 41 } 42 }; 43 44 TestCase error= new TestCase("error") { 45 public void runTest() { 46 throw new Error (); 47 } 48 }; 49 50 TestSuite suite= new TestSuite(); 51 suite.addTest(failure); 52 suite.addTest(error); 53 54 TestSetup wrapper= new TestSetup(suite); 55 56 TestResult result= new TestResult(); 57 wrapper.run(result); 58 59 assertEquals(1, result.failureCount()); 60 assertEquals(1, result.errorCount()); 61 } 62 public void testSetupErrorDontTearDown() { 63 WasRun test= new WasRun(""); 64 65 TornDown wrapper= new TornDown(test) { 66 public void setUp() { 67 fail(); 68 } 69 }; 70 71 TestResult result= new TestResult(); 72 wrapper.run(result); 73 74 assertTrue(!wrapper.fTornDown); 75 } 76 public void testSetupErrorInTestSetup() { 77 WasRun test= new WasRun(""); 78 79 TestSetup wrapper= new TestSetup(test) { 80 public void setUp() { 81 fail(); 82 } 83 }; 84 85 TestResult result= new TestResult(); 86 wrapper.run(result); 87 88 assertTrue(!test.fWasRun); 89 assertTrue(!result.wasSuccessful()); 90 } 91 } | Popular Tags |