diff --git a/core/src/main/java/io/cucumber/core/plugin/TeamCityPlugin.java b/core/src/main/java/io/cucumber/core/plugin/TeamCityPlugin.java index 1af941d9a7..2147d6185c 100644 --- a/core/src/main/java/io/cucumber/core/plugin/TeamCityPlugin.java +++ b/core/src/main/java/io/cucumber/core/plugin/TeamCityPlugin.java @@ -48,6 +48,13 @@ import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; +/** + * Outputs Teamcity services messages to std out. + * + * @see TeamCity + * - Service Messages + */ public class TeamCityPlugin implements EventListener { private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'hh:mm:ss.SSSZ"); @@ -250,22 +257,27 @@ private void printTestStepFinished(TestStepFinished event) { Throwable error = event.getResult().getError(); Status status = event.getResult().getStatus(); switch (status) { - case SKIPPED: - print(TEMPLATE_TEST_IGNORED, timeStamp, duration, error == null ? "Step skipped" : error.getMessage(), - name); + case SKIPPED: { + String message = error == null ? "Step skipped" : error.getMessage(); + print(TEMPLATE_TEST_IGNORED, timeStamp, duration, message, name); break; - case PENDING: - print(TEMPLATE_TEST_IGNORED, timeStamp, duration, error == null ? "Step pending" : error.getMessage(), - name); + } + case PENDING: { + String details = error == null ? "" : error.getMessage(); + print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step pending", details, name); break; - case UNDEFINED: - print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step undefined", getSnippets(currentTestCase), name); + } + case UNDEFINED: { + String snippets = getSnippets(currentTestCase); + print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step undefined", snippets, name); break; + } case AMBIGUOUS: - case FAILED: + case FAILED: { String details = extractStackTrace(error); print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step failed", details, name); break; + } default: break; } diff --git a/core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java b/core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java index 04c1c47bc2..8998c6f739 100755 --- a/core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java +++ b/core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java @@ -1,6 +1,7 @@ package io.cucumber.core.plugin; import io.cucumber.core.backend.StubHookDefinition; +import io.cucumber.core.backend.StubPendingException; import io.cucumber.core.backend.StubStepDefinition; import io.cucumber.core.backend.TestCaseState; import io.cucumber.core.feature.TestFeatureParser; @@ -215,6 +216,28 @@ void should_print_error_message_for_undefined_steps() { "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step undefined' details = 'You can implement this step and 1 other step(s)using the snippet(s) below:|n|ntest snippet 0|ntest snippet 1|n' name = 'first step']")); } + @Test + void should_print_error_message_for_pending_steps() { + Feature feature = TestFeatureParser.parse("path/test.feature", "" + + "Feature: feature name\n" + + " Scenario: scenario name\n" + + " Given first step\n" + + " Given second step\n"); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Runtime.builder() + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new TeamCityPlugin(new PrintStream(out))) + .withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)) + .withBackendSupplier( + new StubBackendSupplier(new StubStepDefinition("first step", new StubPendingException()))) + .build() + .run(); + + assertThat(out, bytesContainsString("" + + "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step pending' details = 'TODO: implement me' name = 'first step']")); + } + @Test void should_print_error_message_for_before_hooks() { Feature feature = TestFeatureParser.parse("path/test.feature", "" +