Skip to content

Commit

Permalink
[Core] Mark pending steps as failed in teamcity plugin
Browse files Browse the repository at this point in the history
The teamcity plugin communicates test results to IntelliJ IDEA using teamcity
service messages[1]. Currently the teamcity plugin marks pending steps as
skipped rather then failed. This is inconsistent with the changes from #1960
in which pending steps are considered a test failure.

 1: https://www.jetbrains.com/help/teamcity/service-messages.html
  • Loading branch information
mpkorstanje committed Mar 14, 2021
1 parent f4ed004 commit c1aa4ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
30 changes: 21 additions & 9 deletions core/src/main/java/io/cucumber/core/plugin/TeamCityPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a
* href=https://www.jetbrains.com/help/teamcity/service-messages.html>TeamCity
* - Service Messages</a>
*/
public class TeamCityPlugin implements EventListener {

private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
Expand Down Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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", "" +
Expand Down

0 comments on commit c1aa4ad

Please sign in to comment.