Skip to content

Commit bc215fe

Browse files
committed
JUnit assume failures behaves just like pending. Closes #359.
1 parent 6c1f853 commit bc215fe

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [master](https://github.com/cucumber/cucumber-jvm/compare/v1.0.11...master)
22

3+
* [Core] JUnit assume failures (`AssumptionViolatedException`) behaves in the same way as pending (`cucumber.runtime.PendingException`) ([#359](https://github.com/cucumber/cucumber-jvm/issues/359) Aslak Hellesøy, Kim Saabye Pedersen)
34
* [Core] Extend url protocols. This makes it possible to load features and glue from within a container such as Arquilian. ([#360](https://github.com/cucumber/cucumber-jvm/issues/360), [#361](https://github.com/cucumber/cucumber-jvm/pull/361) Logan McGrath)
45
* [Jython] Jython Before/After Annotations ([#362](https://github.com/cucumber/cucumber-jvm/pull/362) Stephen Abrams)
56
* [Java] Support for delimited lists in step parameters ([#364](https://github.com/cucumber/cucumber-jvm/issues/364), [#371](https://github.com/cucumber/cucumber-jvm/pull/371) Marquis Wang)

core/src/main/java/cucumber/runtime/Runtime.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.Collection;
2324
import java.util.Collections;
2425
import java.util.List;
@@ -29,6 +30,15 @@
2930
*/
3031
public class Runtime implements UnreportedStepExecutor {
3132

33+
private static final String[] PENDING_EXCEPTIONS = new String[]{
34+
PendingException.class.getName(),
35+
"org.junit.internal.AssumptionViolatedException"
36+
};
37+
38+
static {
39+
Arrays.sort(PENDING_EXCEPTIONS);
40+
}
41+
3242
private static final Object DUMMY_ARG = new Object();
3343
private static final byte ERRORS = 0x1;
3444

@@ -146,7 +156,7 @@ private boolean hasPendingSteps() {
146156

147157
private boolean hasErrors() {
148158
for (Throwable error : errors) {
149-
if (!(error instanceof PendingException)) {
159+
if (!isPending(error)) {
150160
return true;
151161
}
152162
}
@@ -184,7 +194,8 @@ private void runHookIfTagsMatch(HookDefinition hook, Reporter reporter, Set<Tag>
184194
skipNextStep = true;
185195
long duration = System.nanoTime() - start;
186196

187-
Result result = new Result(Result.FAILED, duration, t, DUMMY_ARG);
197+
String status = isPending(t) ? "pending" : Result.FAILED;
198+
Result result = new Result(status, duration, t, DUMMY_ARG);
188199
scenarioResult.add(result);
189200
addError(t);
190201

@@ -256,7 +267,7 @@ public void runStep(String uri, Step step, Reporter reporter, I18n i18n) {
256267
match.runStep(i18n);
257268
} catch (Throwable t) {
258269
error = t;
259-
status = (t instanceof PendingException) ? "pending" : Result.FAILED;
270+
status = isPending(t) ? "pending" : Result.FAILED;
260271
addError(t);
261272
skipNextStep = true;
262273
} finally {
@@ -268,6 +279,10 @@ public void runStep(String uri, Step step, Reporter reporter, I18n i18n) {
268279
}
269280
}
270281

282+
private static boolean isPending(Throwable t) {
283+
return Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0;
284+
}
285+
271286
public void writeStepdefsJson() throws IOException {
272287
glue.writeStepdefsJson(runtimeOptions.featurePaths, runtimeOptions.dotCucumber);
273288
}

core/src/test/java/cucumber/runtime/RuntimeTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import gherkin.formatter.model.Step;
99
import org.junit.Ignore;
1010
import org.junit.Test;
11+
import org.junit.internal.AssumptionViolatedException;
1112

1213
import java.util.Arrays;
1314
import java.util.Collection;
@@ -137,6 +138,14 @@ public void non_strict_with_pending_steps() {
137138
assertEquals(0x0, runtime.exitStatus());
138139
}
139140

141+
@Test
142+
public void non_strict_with_failed_junit_assumption() {
143+
Runtime runtime = createNonStrictRuntime();
144+
runtime.addError(new AssumptionViolatedException("should be treated like pending"));
145+
146+
assertEquals(0x0, runtime.exitStatus());
147+
}
148+
140149
@Test
141150
public void non_strict_with_errors() {
142151
Runtime runtime = createNonStrictRuntime();

0 commit comments

Comments
 (0)