01: package junit.extensions;
02:
03: import junit.framework.Test;
04: import junit.framework.TestResult;
05:
06: /**
07: * A Decorator that runs a test repeatedly.
08: *
09: */
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(
17: "Repetition count must be >= 0");
18: fTimesRepeat = repeat;
19: }
20:
21: @Override
22: public int countTestCases() {
23: return super .countTestCases() * fTimesRepeat;
24: }
25:
26: @Override
27: public void run(TestResult result) {
28: for (int i = 0; i < fTimesRepeat; i++) {
29: if (result.shouldStop())
30: break;
31: super .run(result);
32: }
33: }
34:
35: @Override
36: public String toString() {
37: return super .toString() + "(repeated)";
38: }
39: }
|