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