Skip to content

Commit 589552b

Browse files
committed
Merge pull request #156 from orionll/master
Added possibility to run individual tests
2 parents e15ea09 + 51f036b commit 589552b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,45 @@
22

33
import org.junit.runner.Description;
44
import org.junit.runner.Runner;
5+
import org.junit.runner.manipulation.Filter;
6+
import org.junit.runner.manipulation.Filterable;
7+
import org.junit.runner.manipulation.NoTestsRemainException;
58
import org.junit.runner.notification.Failure;
69
import org.junit.runner.notification.RunNotifier;
710

11+
import fj.P;
812
import fj.P3;
13+
import fj.data.List;
914
import fj.data.Option;
1015
import fj.test.CheckResult;
1116
import fj.test.Property;
1217
import fj.test.reflect.Check;
1318
import fj.test.reflect.CheckParams;
1419

15-
public class PropertyTestRunner extends Runner {
20+
public class PropertyTestRunner extends Runner implements Filterable {
1621
private final Class<?> clas;
22+
private final List<P3<Property, Option<CheckParams>, Description>> allTests;
23+
private volatile List<P3<Property, Option<CheckParams>, Description>> filteredTests;
1724

1825
public PropertyTestRunner(Class<?> clas) {
1926
this.clas = clas;
27+
this.allTests = Check.properties(clas).map(p -> P.p(p._1(), p._3(), Description.createTestDescription(clas, p._2())));
28+
this.filteredTests = allTests;
2029
}
2130

2231
@Override
2332
public Description getDescription() {
2433
Description suite = Description.createSuiteDescription(clas);
25-
for (P3<Property, String, Option<CheckParams>> p : Check.properties(clas)) {
26-
suite.addChild(Description.createTestDescription(clas, p._2()));
27-
}
34+
filteredTests.foreachDoEffect(p -> suite.addChild(p._3()));
2835
return suite;
2936
}
3037

3138
@Override
3239
public void run(RunNotifier notifier) {
33-
for (P3<Property, String, Option<CheckParams>> p : Check.properties(clas)) {
34-
Description desc = Description.createTestDescription(clas, p._2());
40+
filteredTests.foreachDoEffect(p -> {
41+
Description desc = p._3();
3542
notifier.fireTestStarted(desc);
36-
CheckResult result = checkProperty(p._1(), p._3());
43+
CheckResult result = checkProperty(p._1(), p._2());
3744

3845
try {
3946
CheckResult.summaryEx.showS(result);
@@ -42,7 +49,7 @@ public void run(RunNotifier notifier) {
4249
}
4350

4451
notifier.fireTestFinished(desc);
45-
}
52+
});
4653
}
4754

4855
private static CheckResult checkProperty(Property prop, Option<CheckParams> params) {
@@ -52,4 +59,10 @@ private static CheckResult checkProperty(Property prop, Option<CheckParams> para
5259

5360
return prop.check();
5461
}
62+
63+
@Override
64+
public void filter(Filter filter) throws NoTestsRemainException {
65+
filteredTests = allTests.filter(p -> filter.shouldRun(p._3()));
66+
if (filteredTests.isEmpty()) { throw new NoTestsRemainException(); }
67+
}
5568
}

0 commit comments

Comments
 (0)