1 package junit.tests; 2 3 import junit.framework.*; 4 import junit.extensions.RepeatedTest; 5 6 9 10 public class RepeatedTestTest extends TestCase { 11 private TestSuite fSuite; 12 13 public static class SuccessTest extends TestCase { 14 public SuccessTest(String name) { 15 super(name); 16 } 17 18 public void success() { 19 } 20 } 21 22 public RepeatedTestTest(String name) { 23 super(name); 24 fSuite= new TestSuite(); 25 fSuite.addTest(new SuccessTest("success")); 26 fSuite.addTest(new SuccessTest("success")); 27 } 28 29 public void testRepeatedOnce() { 30 Test test= new RepeatedTest(fSuite, 1); 31 assertEquals(2, test.countTestCases()); 32 TestResult result= new TestResult(); 33 test.run(result); 34 assertEquals(2, result.runCount()); 35 } 36 37 public void testRepeatedMoreThanOnce() { 38 Test test= new RepeatedTest(fSuite, 3); 39 assertEquals(6, test.countTestCases()); 40 TestResult result= new TestResult(); 41 test.run(result); 42 assertEquals(6, result.runCount()); 43 } 44 45 public void testRepeatedZero() { 46 Test test= new RepeatedTest(fSuite, 0); 47 assertEquals(0, test.countTestCases()); 48 TestResult result= new TestResult(); 49 test.run(result); 50 assertEquals(0, result.runCount()); 51 } 52 53 public void testRepeatedNegative() { 54 try { 55 Test test= new RepeatedTest(fSuite, -1); 56 } catch (IllegalArgumentException e) { 57 return; 58 } 59 fail("Should throw an IllegalArgumentException"); 60 } 61 } | Popular Tags |