KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > extensions > RepeatedTest


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 JavaDoc("Repetition count must be >= 0");
17         fTimesRepeat= repeat;
18     }
19
20     @Override JavaDoc
21     public int countTestCases() {
22         return super.countTestCases() * fTimesRepeat;
23     }
24
25     @Override JavaDoc
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 JavaDoc
35     public String JavaDoc toString() {
36         return super.toString() + "(repeated)";
37     }
38 }
Popular Tags