1 package junit.tests; 2 3 6 import junit.framework.*; 7 8 public class TestListenerTest extends TestCase implements TestListener { 9 private TestResult fResult; 10 private int fStartCount; 11 private int fEndCount; 12 private int fFailureCount; 13 private int fErrorCount; 14 public TestListenerTest(String name) { 15 super(name); 16 } 17 public void addError(Test test, Throwable t) { 18 fErrorCount++; 19 } 20 public void addFailure(Test test, AssertionFailedError t) { 21 fFailureCount++; 22 } 23 public void endTest(Test test) { 24 fEndCount++; 25 } 26 protected void setUp() { 27 fResult= new TestResult(); 28 fResult.addListener(this); 29 30 fStartCount= 0; 31 fEndCount= 0; 32 fFailureCount= 0; 33 } 34 public void startTest(Test test) { 35 fStartCount++; 36 } 37 public void testError() { 38 TestCase test= new TestCase("noop") { 39 public void runTest() { 40 throw new Error (); 41 } 42 }; 43 test.run(fResult); 44 assertEquals(1, fErrorCount); 45 assertEquals(1, fEndCount); 46 } 47 public void testFailure() { 48 TestCase test= new TestCase("noop") { 49 public void runTest() { 50 fail(); 51 } 52 }; 53 test.run(fResult); 54 assertEquals(1, fFailureCount); 55 assertEquals(1, fEndCount); 56 } 57 public void testStartStop() { 58 TestCase test= new TestCase("noop") { 59 public void runTest() { 60 } 61 }; 62 test.run(fResult); 63 assertEquals(1, fStartCount); 64 assertEquals(1, fEndCount); 65 } 66 } | Popular Tags |