001package junit.extensions; 002 003import junit.framework.Test; 004import junit.framework.TestResult; 005 006/** 007 * A Decorator that runs a test repeatedly. 008 */ 009public class RepeatedTest extends TestDecorator { 010 private int fTimesRepeat; 011 012 public RepeatedTest(Test test, int repeat) { 013 super(test); 014 if (repeat < 0) { 015 throw new IllegalArgumentException("Repetition count must be >= 0"); 016 } 017 fTimesRepeat = repeat; 018 } 019 020 @Override 021 public int countTestCases() { 022 return super.countTestCases() * fTimesRepeat; 023 } 024 025 @Override 026 public void run(TestResult result) { 027 for (int i = 0; i < fTimesRepeat; i++) { 028 if (result.shouldStop()) { 029 break; 030 } 031 super.run(result); 032 } 033 } 034 035 @Override 036 public String toString() { 037 return super.toString() + "(repeated)"; 038 } 039}