20
20
import java .io .PrintStream ;
21
21
import java .util .UUID ;
22
22
23
+ import static io .cucumber .core .backend .HookDefinition .HookType .BEFORE ;
23
24
import static io .cucumber .core .plugin .Bytes .bytes ;
25
+ import static io .cucumber .core .plugin .TeamCityPluginTestStepDefinition .getAnnotationSourceReference ;
26
+ import static io .cucumber .core .plugin .TeamCityPluginTestStepDefinition .getStackSourceReference ;
27
+ import static java .nio .charset .StandardCharsets .UTF_8 ;
24
28
import static java .time .Clock .fixed ;
25
29
import static java .time .Instant .EPOCH ;
26
30
import static java .time .ZoneId .of ;
@@ -72,7 +76,7 @@ void should_handle_scenario_outline() {
72
76
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
73
77
+ "path/test.feature:5' name = 'examples name']\n " +
74
78
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
75
- + "path/test.feature:7' name = 'Example #1.1']\n " +
79
+ + "path/test.feature:7' name = '#1.1: name 1']\n " +
76
80
"##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
77
81
"##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
78
82
+ "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n " +
@@ -83,9 +87,10 @@ void should_handle_scenario_outline() {
83
87
"##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'second step']\n "
84
88
+
85
89
"##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
86
- "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.1']\n " +
90
+ "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.1: name 1']\n "
91
+ +
87
92
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
88
- + "path/test.feature:8' name = 'Example #1.2']\n " +
93
+ + "path/test.feature:8' name = '#1.2: name 2']\n " +
89
94
"##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
90
95
"##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
91
96
+ "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n " +
@@ -96,7 +101,8 @@ void should_handle_scenario_outline() {
96
101
"##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'third step']\n "
97
102
+
98
103
"##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n " +
99
- "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.2']\n " +
104
+ "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.2: name 2']\n "
105
+ +
100
106
"##teamcity[customProgressStatus testsCategory = '' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n "
101
107
+
102
108
"##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'examples name']\n " +
@@ -121,7 +127,7 @@ void should_handle_nameless_attach_events() {
121
127
.withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
122
128
.withBackendSupplier (new StubBackendSupplier (
123
129
singletonList (new StubHookDefinition (
124
- (TestCaseState state ) -> state .attach ("A message" , "text/plain" , null ))),
130
+ (TestCaseState state ) -> state .attach ("A message" . getBytes ( UTF_8 ) , "text/plain" , null ))),
125
131
singletonList (new StubStepDefinition ("first step" )),
126
132
emptyList ()))
127
133
.build ()
@@ -168,7 +174,8 @@ void should_handle_attach_events() {
168
174
.withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
169
175
.withBackendSupplier (new StubBackendSupplier (
170
176
singletonList (new StubHookDefinition (
171
- (TestCaseState state ) -> state .attach ("A message" , "text/plain" , "message.txt" ))),
177
+ (TestCaseState state ) -> state .attach ("A message" .getBytes (UTF_8 ), "text/plain" ,
178
+ "message.txt" ))),
172
179
singletonList (new StubStepDefinition ("first step" )),
173
180
emptyList ()))
174
181
.build ()
@@ -258,17 +265,17 @@ void should_print_error_message_for_before_hooks() {
258
265
.withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
259
266
.withBackendSupplier (new StubBackendSupplier (
260
267
singletonList (
261
- new StubHookDefinition (new StubException ("Step failed" )
268
+ new StubHookDefinition (getAnnotationSourceReference (), BEFORE , new StubException ()
262
269
.withStacktrace ("the stack trace" ))),
263
270
singletonList (new StubStepDefinition ("first step" )),
264
271
emptyList ()))
265
272
.build ()
266
273
.run ();
267
274
268
275
assertThat (out , bytes (containsString ("" +
269
- "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '{stubbed location with details} ' captureStandardOutput = 'true' name = 'Before']\n "
276
+ "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://io.cucumber.core.plugin.TeamCityPluginTestStepDefinition/beforeHook ' captureStandardOutput = 'true' name = 'Before(beforeHook) ']\n "
270
277
+
271
- "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step failed' details = 'Step failed |n\t the stack trace|n' name = 'Before']" )));
278
+ "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step failed' details = 'stub exception |n\t the stack trace|n' name = 'Before(beforeHook) ']" )));
272
279
}
273
280
274
281
@ Test
@@ -284,14 +291,14 @@ void should_print_location_hint_for_java_hooks() {
284
291
.withAdditionalPlugins (new TeamCityPlugin (new PrintStream (out )))
285
292
.withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
286
293
.withBackendSupplier (new StubBackendSupplier (
287
- singletonList (new StubHookDefinition ("com.example.HookDefinition.beforeHook()" )),
294
+ singletonList (new StubHookDefinition (getAnnotationSourceReference (), BEFORE )),
288
295
singletonList (new StubStepDefinition ("first step" )),
289
296
emptyList ()))
290
297
.build ()
291
298
.run ();
292
299
293
300
assertThat (out , bytes (containsString ("" +
294
- "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://com.example.HookDefinition /beforeHook' captureStandardOutput = 'true' name = 'Before(beforeHook)']\n " )));
301
+ "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://io.cucumber.core.plugin.TeamCityPluginTestStepDefinition /beforeHook' captureStandardOutput = 'true' name = 'Before(beforeHook)']\n " )));
295
302
}
296
303
297
304
@ Test
@@ -307,14 +314,14 @@ void should_print_location_hint_for_lambda_hooks() {
307
314
.withAdditionalPlugins (new TeamCityPlugin (new PrintStream (out )))
308
315
.withEventBus (new TimeServiceEventBus (fixed (EPOCH , of ("UTC" )), UUID ::randomUUID ))
309
316
.withBackendSupplier (new StubBackendSupplier (
310
- singletonList (new StubHookDefinition ("com.example.HookDefinition.<init>(HookDefinition.java:12)" )),
317
+ singletonList (new StubHookDefinition (getStackSourceReference (), BEFORE )),
311
318
singletonList (new StubStepDefinition ("first step" )),
312
319
emptyList ()))
313
320
.build ()
314
321
.run ();
315
322
316
323
assertThat (out , bytes (containsString ("" +
317
- "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://com.example.HookDefinition/HookDefinition ' captureStandardOutput = 'true' name = 'Before(HookDefinition )']\n " )));
324
+ "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = 'java:test://io.cucumber.core.plugin.TeamCityPluginTestStepDefinition/TeamCityPluginTestStepDefinition ' captureStandardOutput = 'true' name = 'Before(TeamCityPluginTestStepDefinition )']\n " )));
318
325
}
319
326
320
327
@ Test
@@ -397,4 +404,5 @@ void should_print_comparison_failure_for_failed_assert_equal_with_prefix() {
397
404
assertThat (out ,
398
405
bytes (containsString ("expected = 'one value' actual = 'another value' name = 'first step']" )));
399
406
}
407
+
400
408
}
0 commit comments