Skip to content

Commit 27f9b33

Browse files
committed
[JUnit] Only report the first failed assumption
The junit-vintage implementation of junit-5 reports multiple failed assumptions as a MultipleFailure and treats it as a failure of the test case. As such we can only provide the first failed assumption.
1 parent 150ae65 commit 27f9b33

File tree

5 files changed

+46
-27
lines changed

5 files changed

+46
-27
lines changed

junit/src/main/java/io/cucumber/junit/api/JUnitReporter.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ void handleTestCaseResult(Result result) {
160160
if (stepErrors.isEmpty()) {
161161
stepErrors.add(new SkippedThrowable(SCENARIO));
162162
}
163-
for (Throwable error : stepErrors) {
164-
pickleRunnerNotifier.addFailedAssumption(error);
165-
}
163+
stepErrors.stream()
164+
.findFirst()
165+
.ifPresent(error -> pickleRunnerNotifier.addFailedAssumption(error));
166166
break;
167167
case PENDING:
168168
case UNDEFINED:
169-
for (Throwable error : stepErrors) {
170-
addFailureOrFailedAssumptionDependingOnStrictMode(pickleRunnerNotifier, error);
171-
}
169+
stepErrors.stream()
170+
.findFirst()
171+
.ifPresent(error -> addFailureOrFailedAssumptionDependingOnStrictMode(pickleRunnerNotifier, error));
172172
break;
173173
case AMBIGUOUS:
174174
case FAILED:

junit/src/test/java/io/cucumber/junit/api/FeatureRunnerTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ public void should_not_issue_notification_for_steps_by_default_scenario_outline_
108108
InOrder order = inOrder(notifier);
109109

110110
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario outline name(feature name)")));
111-
order.verify(notifier, times(3)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario outline name(feature name)")));
111+
order.verify(notifier, times(1)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario outline name(feature name)")));
112112
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario outline name(feature name)")));
113113
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario outline name(feature name)")));
114-
order.verify(notifier, times(3)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario outline name(feature name)")));
114+
order.verify(notifier, times(1)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario outline name(feature name)")));
115115
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario outline name(feature name)")));
116116
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario outline name(feature name)")));
117-
order.verify(notifier, times(3)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario outline name(feature name)")));
117+
order.verify(notifier, times(1)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario outline name(feature name)")));
118118
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario outline name(feature name)")));
119119
}
120120

@@ -135,10 +135,10 @@ public void should_not_issue_notification_for_steps_by_default_two_scenarios_wit
135135
InOrder order = inOrder(notifier);
136136

137137
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_1 name(feature name)")));
138-
order.verify(notifier, times(3)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario_1 name(feature name)")));
138+
order.verify(notifier, times(1)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario_1 name(feature name)")));
139139
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_1 name(feature name)")));
140140
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_2 name(feature name)")));
141-
order.verify(notifier, times(2)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario_2 name(feature name)")));
141+
order.verify(notifier, times(1)).fireTestAssumptionFailed(argThat(new FailureMatcher("scenario_2 name(feature name)")));
142142
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_2 name(feature name)")));
143143
}
144144

junit/src/test/java/io/cucumber/junit/api/JUnitReporterTest.java

+5-15
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,12 @@ public void test_case_finished_fires_assumption_failed_and_test_finished_for_ski
334334
jUnitReporter.handleTestCaseResult(result);
335335

336336
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
337-
verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
337+
verify(runNotifier, times(1)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
338338
verify(runNotifier).fireTestFinished(description);
339339

340340
List<Failure> failures = failureArgumentCaptor.getAllValues();
341341
assertEquals(description, failures.get(0).getDescription());
342342
assertEquals(exception1, failures.get(0).getException());
343-
assertEquals(description, failures.get(1).getDescription());
344-
assertEquals(exception2, failures.get(1).getException());
345343
}
346344

347345
@Test
@@ -357,14 +355,12 @@ public void test_case_finished_fires_assumption_failed_and_test_finished_for_pen
357355
jUnitReporter.handleTestCaseResult(result);
358356

359357
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
360-
verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
358+
verify(runNotifier, times(1)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
361359
verify(runNotifier).fireTestFinished(description);
362360

363361
List<Failure> failures = failureArgumentCaptor.getAllValues();
364362
assertEquals(description, failures.get(0).getDescription());
365363
assertEquals(exception1, failures.get(0).getException());
366-
assertEquals(description, failures.get(1).getDescription());
367-
assertEquals(exception2, failures.get(1).getException());
368364
}
369365

370366
@Test
@@ -380,14 +376,12 @@ public void test_case_finished_fires_failure_and_test_finished_for_pending_step_
380376
jUnitReporter.handleTestCaseResult(result);
381377

382378
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
383-
verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
379+
verify(runNotifier, times(1)).fireTestFailure(failureArgumentCaptor.capture());
384380
verify(runNotifier).fireTestFinished(description);
385381

386382
List<Failure> failures = failureArgumentCaptor.getAllValues();
387383
assertEquals(description, failures.get(0).getDescription());
388384
assertEquals(exception1, failures.get(0).getException());
389-
assertEquals(description, failures.get(1).getDescription());
390-
assertEquals(exception2, failures.get(1).getException());
391385
}
392386

393387
@Test
@@ -403,14 +397,12 @@ public void test_case_finished_fires_assumption_failed_and_test_finished_for_und
403397
jUnitReporter.handleTestCaseResult(result);
404398

405399
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
406-
verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
400+
verify(runNotifier, times(1)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
407401
verify(runNotifier).fireTestFinished(description);
408402

409403
List<Failure> failures = failureArgumentCaptor.getAllValues();
410404
assertEquals(description, failures.get(0).getDescription());
411405
assertEquals(exception1, failures.get(0).getException());
412-
assertEquals(description, failures.get(1).getDescription());
413-
assertEquals(exception2, failures.get(1).getException());
414406
}
415407

416408
@Test
@@ -426,14 +418,12 @@ public void test_case_finished_fires_failure_and_test_finished_for_undefined_ste
426418
jUnitReporter.handleTestCaseResult(result);
427419

428420
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
429-
verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
421+
verify(runNotifier, times(1)).fireTestFailure(failureArgumentCaptor.capture());
430422
verify(runNotifier).fireTestFinished(description);
431423

432424
List<Failure> failures = failureArgumentCaptor.getAllValues();
433425
assertEquals(description, failures.get(0).getDescription());
434426
assertEquals(exception1, failures.get(0).getException());
435-
assertEquals(description, failures.get(1).getDescription());
436-
assertEquals(exception2, failures.get(1).getException());
437427
}
438428

439429
@Test

picocontainer/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<arg value="--plugin" />
5858
<arg value="progress" />
5959
<arg value="--glue" />
60-
<arg value="cucumber.runtime.java.picocontainer" />
60+
<arg value="io.cucumber.picocontainer" />
6161
<arg value="${basedir}/src/test/resources/io/cucumber/picocontainer" />
6262
</java>
6363
</target>

pom.xml

+29
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,35 @@
634634
</configuration>
635635
</plugin>
636636

637+
<plugin>
638+
<groupId>org.apache.maven.plugins</groupId>
639+
<artifactId>maven-surefire-plugin</artifactId>
640+
<configuration>
641+
<argLine>-Duser.language=en</argLine>
642+
<argLine>-Xmx1024m</argLine>
643+
<argLine>-XX:MaxPermSize=256m</argLine>
644+
<argLine>-Dfile.encoding=UTF-8</argLine>
645+
<useFile>false</useFile>
646+
</configuration>
647+
<dependencies>
648+
<dependency>
649+
<groupId>org.junit.jupiter</groupId>
650+
<artifactId>junit-jupiter-engine</artifactId>
651+
<version>${junit-jupiter.version}</version>
652+
</dependency>
653+
<dependency>
654+
<groupId>org.junit.platform</groupId>
655+
<artifactId>junit-platform-engine</artifactId>
656+
<version>${junit-platform.version}</version>
657+
</dependency>
658+
<dependency>
659+
<groupId>org.junit.vintage</groupId>
660+
<artifactId>junit-vintage-engine</artifactId>
661+
<version>${junit-jupiter.version}</version>
662+
</dependency>
663+
</dependencies>
664+
</plugin>
665+
637666
<plugin>
638667
<groupId>org.apache.maven.plugins</groupId>
639668
<artifactId>maven-war-plugin</artifactId>

0 commit comments

Comments
 (0)