1 package junitx.extensions; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestResult; 6 7 11 public class TestSetupTest 12 extends TestCase { 13 14 public TestSetupTest(String name) { 15 super(name); 16 } 17 18 public void testFailSetUp() { 19 TestCase testcase = new TestCase("testDummy") { 20 public void testDummy() { 21 System.out.println("h"); 22 } 23 }; 24 25 MockSetUp wrapper = new MockSetUp(testcase); 26 TestResult result = new TestResult(); 27 28 wrapper.run(result); 29 assertTrue(wrapper.tearDownExecuted); 30 } 31 32 public void testFailRun() { 33 TestCase testcase = new TestCase("testDummy") { 34 public void testDummy() { 35 throw new NullPointerException (); 36 } 37 }; 38 39 MockSetUp wrapper = new MockSetUp(testcase); 40 TestResult result = new TestResult(); 41 42 wrapper.run(result); 43 assertTrue(wrapper.tearDownExecuted); 44 } 45 46 public static class MockSetUp 47 extends TestSetup { 48 public boolean tearDownExecuted = false; 49 50 public MockSetUp(Test test) { 51 super(test); 52 } 53 54 protected void setUp() 55 throws Exception { 56 throw new NullPointerException (); 57 } 58 59 protected void tearDown() 60 throws Exception { 61 tearDownExecuted = true; 62 } 63 } 64 65 } 66 | Popular Tags |