|
24 | 24 | import io.cucumber.core.runtime.FeaturePathFeatureSupplier; |
25 | 25 | import io.cucumber.core.runtime.Runtime; |
26 | 26 | import io.cucumber.core.runtime.TimeServiceEventBus; |
| 27 | +import io.cucumber.plugin.event.Result; |
| 28 | +import io.cucumber.plugin.event.TestRunFinished; |
27 | 29 | import io.github.glytching.junit.extension.system.SystemProperty; |
28 | 30 | import io.github.glytching.junit.extension.system.SystemPropertyExtension; |
29 | 31 | import io.qameta.allure.Description; |
|
47 | 49 | import org.junit.jupiter.api.Test; |
48 | 50 | import org.junit.jupiter.api.extension.ExtendWith; |
49 | 51 | import org.junit.jupiter.api.parallel.ResourceLock; |
| 52 | +import org.junit.jupiter.params.ParameterizedTest; |
| 53 | +import org.junit.jupiter.params.provider.Arguments; |
| 54 | +import org.junit.jupiter.params.provider.MethodSource; |
| 55 | +import org.opentest4j.AssertionFailedError; |
50 | 56 |
|
51 | 57 | import java.time.Clock; |
| 58 | +import java.time.Duration; |
52 | 59 | import java.time.Instant; |
53 | 60 | import java.util.ArrayList; |
54 | 61 | import java.util.Arrays; |
|
57 | 64 | import java.util.function.Consumer; |
58 | 65 | import java.util.function.Supplier; |
59 | 66 | import java.util.stream.Collectors; |
| 67 | +import java.util.stream.Stream; |
60 | 68 |
|
61 | 69 | import static io.qameta.allure.util.ResultsUtils.PACKAGE_LABEL_NAME; |
62 | 70 | import static io.qameta.allure.util.ResultsUtils.PARENT_SUITE_LABEL_NAME; |
@@ -1057,6 +1065,60 @@ private AllureResults runFeature(final String featureResource, |
1057 | 1065 | }); |
1058 | 1066 | } |
1059 | 1067 |
|
| 1068 | + @ParameterizedTest |
| 1069 | + @MethodSource("runErrorStatuses") |
| 1070 | + void shouldClassifyRunErrorsUsingCucumberOutcome(final io.cucumber.plugin.event.Status outcome, |
| 1071 | + final Throwable throwable, final Status status) { |
| 1072 | + final AllureResults results = runFinished(new Result(outcome, Duration.ZERO, throwable)); |
| 1073 | + assertThat(getGlobalErrors(results)).singleElement().satisfies(error -> { |
| 1074 | + assertThat(error.getStatus()).isEqualTo(status); |
| 1075 | + assertThat(error.getTrace()).contains(throwable.getClass().getName()); |
| 1076 | + if (throwable instanceof AssertionFailedError) { |
| 1077 | + assertThat(error.getActual()).startsWith("actual ("); |
| 1078 | + assertThat(error.getExpected()).startsWith("expected ("); |
| 1079 | + } |
| 1080 | + }); |
| 1081 | + assertThat(results.getTestResults()).isEmpty(); |
| 1082 | + } |
| 1083 | + |
| 1084 | + static Stream<Arguments> runErrorStatuses() { |
| 1085 | + return Stream.of( |
| 1086 | + Arguments.of( |
| 1087 | + io.cucumber.plugin.event.Status.FAILED, |
| 1088 | + new AssertionFailedError("comparison", "expected", "actual"), Status.FAILED |
| 1089 | + ), |
| 1090 | + Arguments.of( |
| 1091 | + io.cucumber.plugin.event.Status.FAILED, |
| 1092 | + new IllegalStateException("runtime"), Status.BROKEN |
| 1093 | + ), |
| 1094 | + Arguments.of(io.cucumber.plugin.event.Status.SKIPPED, new AssertionError("skip"), Status.BROKEN), |
| 1095 | + Arguments.of(io.cucumber.plugin.event.Status.PENDING, new AssertionError("pending"), Status.BROKEN), |
| 1096 | + Arguments.of(io.cucumber.plugin.event.Status.AMBIGUOUS, new AssertionError("ambiguous"), Status.BROKEN), |
| 1097 | + Arguments.of(io.cucumber.plugin.event.Status.UNDEFINED, new AssertionError("undefined"), Status.BROKEN), |
| 1098 | + Arguments.of(io.cucumber.plugin.event.Status.PASSED, new AssertionError("runtime signal"), Status.BROKEN) |
| 1099 | + ); |
| 1100 | + } |
| 1101 | + |
| 1102 | + @Test |
| 1103 | + void shouldNotCreateGlobalWhenRunResultHasNoThrowable() { |
| 1104 | + assertThat(runFinished(new Result(io.cucumber.plugin.event.Status.FAILED, Duration.ZERO, null)).getGlobals()) |
| 1105 | + .isEmpty(); |
| 1106 | + } |
| 1107 | + |
| 1108 | + @Test |
| 1109 | + void shouldNotCreateGlobalWhenRunResultIsAbsent() { |
| 1110 | + assertThat(runFinished(null).getGlobals()).isEmpty(); |
| 1111 | + } |
| 1112 | + |
| 1113 | + private static AllureResults runFinished(final Result result) { |
| 1114 | + return RunUtils.runTests(lifecycle -> { |
| 1115 | + final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID); |
| 1116 | + final AllureCucumber7Jvm adapter = new AllureCucumber7Jvm(lifecycle); |
| 1117 | + adapter.setEventPublisher(bus); |
| 1118 | + bus.send(result == null ? new TestRunFinished(Instant.now()) : new TestRunFinished(Instant.now(), result)); |
| 1119 | + }); |
| 1120 | + } |
| 1121 | + |
1060 | 1122 | private static List<GlobalError> getGlobalErrors(final AllureResults results) { |
1061 | 1123 | return results.getGlobals().stream() |
1062 | 1124 | .flatMap(globals -> globals.getErrors().stream()) |
|
0 commit comments