1 package junit.tests.framework; 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 15 public void addError(Test test, Throwable t) { 16 fErrorCount++; 17 } 18 public void addFailure(Test test, AssertionFailedError t) { 19 fFailureCount++; 20 } 21 public void endTest(Test test) { 22 fEndCount++; 23 } 24 protected void setUp() { 25 fResult= new TestResult(); 26 fResult.addListener(this); 27 28 fStartCount= 0; 29 fEndCount= 0; 30 fFailureCount= 0; 31 } 32 public void startTest(Test test) { 33 fStartCount++; 34 } 35 public void testError() { 36 TestCase test= new TestCase("noop") { 37 public void runTest() { 38 throw new Error (); 39 } 40 }; 41 test.run(fResult); 42 assertEquals(1, fErrorCount); 43 assertEquals(1, fEndCount); 44 } 45 public void testFailure() { 46 TestCase test= new TestCase("noop") { 47 public void runTest() { 48 fail(); 49 } 50 }; 51 test.run(fResult); 52 assertEquals(1, fFailureCount); 53 assertEquals(1, fEndCount); 54 } 55 public void testStartStop() { 56 TestCase test= new TestCase("noop") { 57 public void runTest() { 58 } 59 }; 60 test.run(fResult); 61 assertEquals(1, fStartCount); 62 assertEquals(1, fEndCount); 63 } 64 } | Popular Tags |