Home | History | Annotate | Download | only in extensions
      1 package junit.extensions;
      2 
      3 import junit.framework.Test;
      4 import junit.framework.TestResult;
      5 
      6 /**
      7  * A Decorator that runs a test repeatedly.
      8  *
      9  */
     10 public class RepeatedTest extends TestDecorator {
     11 	private int fTimesRepeat;
     12 
     13 	public RepeatedTest(Test test, int repeat) {
     14 		super(test);
     15 		if (repeat < 0)
     16 			throw new IllegalArgumentException("Repetition count must be >= 0");
     17 		fTimesRepeat= repeat;
     18 	}
     19 
     20 	@Override
     21 	public int countTestCases() {
     22 		return super.countTestCases() * fTimesRepeat;
     23 	}
     24 
     25 	@Override
     26 	public void run(TestResult result) {
     27 		for (int i= 0; i < fTimesRepeat; i++) {
     28 			if (result.shouldStop())
     29 				break;
     30 			super.run(result);
     31 		}
     32 	}
     33 
     34 	@Override
     35 	public String toString() {
     36 		return super.toString() + "(repeated)";
     37 	}
     38 }