20
20
import java .util .Set ;
21
21
22
22
import static java .util .Arrays .asList ;
23
+ import static org .junit .Assert .assertEquals ;
23
24
import static org .junit .Assert .assertTrue ;
24
25
import static org .mockito .Matchers .argThat ;
25
26
import static org .mockito .Mockito .inOrder ;
26
27
import static org .mockito .Mockito .mock ;
28
+ import static org .mockito .Mockito .times ;
27
29
28
30
public class FeatureRunnerTest {
29
31
30
32
@ Test
31
- public void should_call_formatter_for_two_scenarios_with_background () throws Throwable {
33
+ public void should_not_issue_notification_for_steps_by_default_two_scenarios_with_background () throws Throwable {
32
34
CucumberFeature feature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
33
35
"Feature: feature name\n " +
34
36
" Background: background\n " +
@@ -43,19 +45,85 @@ public void should_call_formatter_for_two_scenarios_with_background() throws Thr
43
45
44
46
InOrder order = inOrder (notifier );
45
47
48
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario_1 name(feature name)" )));
49
+ order .verify (notifier , times (3 )).fireTestAssumptionFailed (argThat (new FailureMatcher ("scenario_1 name(feature name)" )));
50
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario_1 name(feature name)" )));
51
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario_2 name(feature name)" )));
52
+ order .verify (notifier , times (2 )).fireTestAssumptionFailed (argThat (new FailureMatcher ("scenario_2 name(feature name)" )));
53
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario_2 name(feature name)" )));
54
+ }
55
+
56
+ @ Test
57
+ public void should_not_issue_notification_for_steps_by_default_scenario_outline_with_two_examples_table_and_background () throws Throwable {
58
+ CucumberFeature feature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
59
+ "Feature: feature name\n " +
60
+ " Background: background\n " +
61
+ " Given first step\n " +
62
+ " Scenario Outline: scenario outline name\n " +
63
+ " When <x> step\n " +
64
+ " Then <y> step\n " +
65
+ " Examples: examples 1 name\n " +
66
+ " | x | y |\n " +
67
+ " | second | third |\n " +
68
+ " | second | third |\n " +
69
+ " Examples: examples 2 name\n " +
70
+ " | x | y |\n " +
71
+ " | second | third |\n " );
72
+
73
+ RunNotifier notifier = runFeatureWithNotifier (feature );
74
+
75
+ InOrder order = inOrder (notifier );
76
+
77
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario outline name(feature name)" )));
78
+ order .verify (notifier , times (3 )).fireTestAssumptionFailed (argThat (new FailureMatcher ("scenario outline name(feature name)" )));
79
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario outline name(feature name)" )));
80
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario outline name(feature name)" )));
81
+ order .verify (notifier , times (3 )).fireTestAssumptionFailed (argThat (new FailureMatcher ("scenario outline name(feature name)" )));
82
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario outline name(feature name)" )));
83
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario outline name(feature name)" )));
84
+ order .verify (notifier , times (3 )).fireTestAssumptionFailed (argThat (new FailureMatcher ("scenario outline name(feature name)" )));
85
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario outline name(feature name)" )));
86
+ }
87
+
88
+ @ Test
89
+ public void step_notification_can_be_turned_on_two_scenarios_with_background () throws Throwable {
90
+ CucumberFeature feature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
91
+ "Feature: feature name\n " +
92
+ " Background: background\n " +
93
+ " Given first step\n " +
94
+ " Scenario: scenario_1 name\n " +
95
+ " When second step\n " +
96
+ " Then third step\n " +
97
+ " Scenario: scenario_2 name\n " +
98
+ " Then another second step\n " );
99
+
100
+ RunNotifier notifier = runFeatureWithNotifier (feature , "--step-notifications" );
101
+
102
+ InOrder order = inOrder (notifier );
103
+
46
104
order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario_1 name" )));
105
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("first step(scenario_1 name)" )));
47
106
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("first step(scenario_1 name)" )));
107
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("first step(scenario_1 name)" )));
108
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("second step(scenario_1 name)" )));
48
109
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("second step(scenario_1 name)" )));
110
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("second step(scenario_1 name)" )));
111
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("third step(scenario_1 name)" )));
49
112
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("third step(scenario_1 name)" )));
113
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("third step(scenario_1 name)" )));
50
114
order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario_1 name" )));
51
115
order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario_2 name" )));
116
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("first step(scenario_2 name)" )));
52
117
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("first step(scenario_2 name)" )));
118
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("first step(scenario_2 name)" )));
119
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("another second step(scenario_2 name)" )));
53
120
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("another second step(scenario_2 name)" )));
121
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("another second step(scenario_2 name)" )));
54
122
order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario_2 name" )));
55
123
}
56
124
57
125
@ Test
58
- public void should_call_formatter_for_scenario_outline_with_two_examples_table_and_background () throws Throwable {
126
+ public void step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background () throws Throwable {
59
127
CucumberFeature feature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
60
128
"Feature: feature name\n " +
61
129
" Background: background\n " +
@@ -71,29 +139,47 @@ public void should_call_formatter_for_scenario_outline_with_two_examples_table_a
71
139
" | x | y |\n " +
72
140
" | second | third |\n " );
73
141
74
- RunNotifier notifier = runFeatureWithNotifier (feature );
142
+ RunNotifier notifier = runFeatureWithNotifier (feature , "--step-notifications" );
75
143
76
144
InOrder order = inOrder (notifier );
77
145
78
146
order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario outline name" )));
147
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("first step(scenario outline name)" )));
79
148
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("first step(scenario outline name)" )));
149
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("first step(scenario outline name)" )));
150
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("second step(scenario outline name)" )));
80
151
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("second step(scenario outline name)" )));
152
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("second step(scenario outline name)" )));
153
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("third step(scenario outline name)" )));
81
154
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("third step(scenario outline name)" )));
155
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("third step(scenario outline name)" )));
82
156
order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario outline name" )));
83
157
order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario outline name" )));
158
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("first step(scenario outline name)" )));
84
159
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("first step(scenario outline name)" )));
160
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("first step(scenario outline name)" )));
161
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("second step(scenario outline name)" )));
85
162
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("second step(scenario outline name)" )));
163
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("second step(scenario outline name)" )));
164
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("third step(scenario outline name)" )));
86
165
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("third step(scenario outline name)" )));
166
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("third step(scenario outline name)" )));
87
167
order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario outline name" )));
88
168
order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("scenario outline name" )));
169
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("first step(scenario outline name)" )));
89
170
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("first step(scenario outline name)" )));
171
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("first step(scenario outline name)" )));
172
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("second step(scenario outline name)" )));
90
173
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("second step(scenario outline name)" )));
174
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("second step(scenario outline name)" )));
175
+ order .verify (notifier ).fireTestStarted (argThat (new DescriptionMatcher ("third step(scenario outline name)" )));
91
176
order .verify (notifier ).fireTestAssumptionFailed (argThat (new FailureMatcher ("third step(scenario outline name)" )));
177
+ order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("third step(scenario outline name)" )));
92
178
order .verify (notifier ).fireTestFinished (argThat (new DescriptionMatcher ("scenario outline name" )));
93
179
}
94
180
95
- private RunNotifier runFeatureWithNotifier (CucumberFeature cucumberFeature ) throws InitializationError {
96
- FeatureRunner runner = createFeatureRunner (cucumberFeature );
181
+ private RunNotifier runFeatureWithNotifier (CucumberFeature cucumberFeature , String ... options ) throws InitializationError {
182
+ FeatureRunner runner = createFeatureRunner (cucumberFeature , options );
97
183
RunNotifier notifier = mock (RunNotifier .class );
98
184
runner .run (notifier );
99
185
return notifier ;
@@ -116,7 +202,7 @@ private FeatureRunner createFeatureRunner(CucumberFeature cucumberFeature, JUnit
116
202
117
203
118
204
@ Test
119
- public void shouldPopulateDescriptionsWithStableUniqueIds () throws Exception {
205
+ public void should_populate_descriptions_with_stable_unique_ids () throws Exception {
120
206
CucumberFeature cucumberFeature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
121
207
"Feature: feature name\n " +
122
208
" Background:\n " +
@@ -146,7 +232,7 @@ public void shouldPopulateDescriptionsWithStableUniqueIds() throws Exception {
146
232
}
147
233
148
234
@ Test
149
- public void shouldNotCreateStepDescriptions () throws Exception {
235
+ public void should_not_create_step_descriptions_by_default () throws Exception {
150
236
CucumberFeature cucumberFeature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
151
237
"Feature: feature name\n " +
152
238
" Background:\n " +
@@ -165,7 +251,7 @@ public void shouldNotCreateStepDescriptions() throws Exception {
165
251
166
252
);
167
253
168
- FeatureRunner runner = createFeatureRunner (cucumberFeature , "--no-step-notifications" );
254
+ FeatureRunner runner = createFeatureRunner (cucumberFeature );
169
255
170
256
Description feature = runner .getDescription ();
171
257
Description scenarioA = feature .getChildren ().get (0 );
@@ -180,6 +266,41 @@ public void shouldNotCreateStepDescriptions() throws Exception {
180
266
assertTrue (scenarioC2 .getChildren ().isEmpty ());
181
267
}
182
268
269
+ @ Test
270
+ public void step_descriptions_can_be_turned_on () throws Exception {
271
+ CucumberFeature cucumberFeature = TestPickleBuilder .parseFeature ("path/test.feature" , "" +
272
+ "Feature: feature name\n " +
273
+ " Background:\n " +
274
+ " Given background step\n " +
275
+ " Scenario: A\n " +
276
+ " Then scenario name\n " +
277
+ " Scenario: B\n " +
278
+ " Then scenario name\n " +
279
+ " Scenario Outline: C\n " +
280
+ " Then scenario <name>\n " +
281
+ " Examples:\n " +
282
+ " | name |\n " +
283
+ " | C |\n " +
284
+ " | D |\n " +
285
+ " | E |\n "
286
+
287
+ );
288
+
289
+ FeatureRunner runner = createFeatureRunner (cucumberFeature , "--step-notifications" );
290
+
291
+ Description feature = runner .getDescription ();
292
+ Description scenarioA = feature .getChildren ().get (0 );
293
+ assertEquals (2 , scenarioA .getChildren ().size ());
294
+ Description scenarioB = feature .getChildren ().get (1 );
295
+ assertEquals (2 , scenarioB .getChildren ().size ());
296
+ Description scenarioC0 = feature .getChildren ().get (2 );
297
+ assertEquals (2 , scenarioC0 .getChildren ().size ());
298
+ Description scenarioC1 = feature .getChildren ().get (3 );
299
+ assertEquals (2 , scenarioC1 .getChildren ().size ());
300
+ Description scenarioC2 = feature .getChildren ().get (4 );
301
+ assertEquals (2 , scenarioC2 .getChildren ().size ());
302
+ }
303
+
183
304
private static void assertDescriptionIsUnique (Description description , Set <Description > descriptions ) {
184
305
// Note: JUnit uses the the serializable parameter as the unique id when comparing Descriptions
185
306
assertTrue (descriptions .add (description ));
0 commit comments