Skip to content

Commit c1aa4ad

Browse files
committed
[Core] Mark pending steps as failed in teamcity plugin
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
1 parent f4ed004 commit c1aa4ad

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

Diff for: core/src/main/java/io/cucumber/core/plugin/TeamCityPlugin.java

+21-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
import static java.util.Collections.emptyList;
4949
import static java.util.stream.Collectors.joining;
5050

51+
/**
52+
* Outputs Teamcity services messages to std out.
53+
*
54+
* @see <a
55+
* href=https://www.jetbrains.com/help/teamcity/service-messages.html>TeamCity
56+
* - Service Messages</a>
57+
*/
5158
public class TeamCityPlugin implements EventListener {
5259

5360
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) {
250257
Throwable error = event.getResult().getError();
251258
Status status = event.getResult().getStatus();
252259
switch (status) {
253-
case SKIPPED:
254-
print(TEMPLATE_TEST_IGNORED, timeStamp, duration, error == null ? "Step skipped" : error.getMessage(),
255-
name);
260+
case SKIPPED: {
261+
String message = error == null ? "Step skipped" : error.getMessage();
262+
print(TEMPLATE_TEST_IGNORED, timeStamp, duration, message, name);
256263
break;
257-
case PENDING:
258-
print(TEMPLATE_TEST_IGNORED, timeStamp, duration, error == null ? "Step pending" : error.getMessage(),
259-
name);
264+
}
265+
case PENDING: {
266+
String details = error == null ? "" : error.getMessage();
267+
print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step pending", details, name);
260268
break;
261-
case UNDEFINED:
262-
print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step undefined", getSnippets(currentTestCase), name);
269+
}
270+
case UNDEFINED: {
271+
String snippets = getSnippets(currentTestCase);
272+
print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step undefined", snippets, name);
263273
break;
274+
}
264275
case AMBIGUOUS:
265-
case FAILED:
276+
case FAILED: {
266277
String details = extractStackTrace(error);
267278
print(TEMPLATE_TEST_FAILED, timeStamp, duration, "Step failed", details, name);
268279
break;
280+
}
269281
default:
270282
break;
271283
}

Diff for: core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.cucumber.core.plugin;
22

33
import io.cucumber.core.backend.StubHookDefinition;
4+
import io.cucumber.core.backend.StubPendingException;
45
import io.cucumber.core.backend.StubStepDefinition;
56
import io.cucumber.core.backend.TestCaseState;
67
import io.cucumber.core.feature.TestFeatureParser;
@@ -215,6 +216,28 @@ void should_print_error_message_for_undefined_steps() {
215216
"##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']"));
216217
}
217218

219+
@Test
220+
void should_print_error_message_for_pending_steps() {
221+
Feature feature = TestFeatureParser.parse("path/test.feature", "" +
222+
"Feature: feature name\n" +
223+
" Scenario: scenario name\n" +
224+
" Given first step\n" +
225+
" Given second step\n");
226+
227+
ByteArrayOutputStream out = new ByteArrayOutputStream();
228+
Runtime.builder()
229+
.withFeatureSupplier(new StubFeatureSupplier(feature))
230+
.withAdditionalPlugins(new TeamCityPlugin(new PrintStream(out)))
231+
.withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID))
232+
.withBackendSupplier(
233+
new StubBackendSupplier(new StubStepDefinition("first step", new StubPendingException())))
234+
.build()
235+
.run();
236+
237+
assertThat(out, bytesContainsString("" +
238+
"##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step pending' details = 'TODO: implement me' name = 'first step']"));
239+
}
240+
218241
@Test
219242
void should_print_error_message_for_before_hooks() {
220243
Feature feature = TestFeatureParser.parse("path/test.feature", "" +

0 commit comments

Comments
 (0)