Skip to content

Commit eba9a56

Browse files
committed
v2版本添加功能RepeatedTest
1 parent 9024208 commit eba9a56

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.litejunit.extension;
2+
3+
import org.litejunit.v2.Test;
4+
import org.litejunit.v2.TestResult;
5+
6+
/**
7+
* Created by john on 2017/9/2.
8+
*/
9+
public class RepeatedTest extends TestDecorator {
10+
private int fTimesRepeat;
11+
12+
public RepeatedTest(Test test, int repeat) {
13+
super(test);
14+
if (repeat < 0)
15+
throw new IllegalArgumentException("Repetition count must be > 0");
16+
fTimesRepeat = repeat;
17+
}
18+
19+
public int countTestCases() {
20+
return super.countTestCases() * fTimesRepeat;
21+
}
22+
23+
public void run(TestResult result) {
24+
for (int i = 0; i < fTimesRepeat; i++) {
25+
if (result.shouldStop())
26+
break;
27+
super.run(result);
28+
}
29+
}
30+
31+
public String toString() {
32+
return super.toString() + "(repeated)";
33+
}
34+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.litejunit.extension;
2+
3+
import org.litejunit.v2.Assert;
4+
import org.litejunit.v2.Test;
5+
import org.litejunit.v2.TestResult;
6+
7+
/**
8+
* Created by john on 2017/9/2.
9+
*/
10+
public class TestDecorator extends Assert implements Test {
11+
protected Test test;
12+
13+
public TestDecorator(Test test) {
14+
this.test = test;
15+
}
16+
17+
/**
18+
* The basic run behaviour.
19+
*/
20+
public void basicRun(TestResult result) {
21+
test.run(result);
22+
}
23+
24+
public int countTestCases() {
25+
return test.countTestCases();
26+
}
27+
28+
public void run(TestResult result) {
29+
basicRun(result);
30+
}
31+
32+
public String toString() {
33+
return test.toString();
34+
}
35+
36+
public Test getTest() {
37+
return test;
38+
}
39+
}

0 commit comments

Comments
 (0)