36
36
import java .time .ZoneOffset ;
37
37
import java .time .format .DateTimeFormatter ;
38
38
import java .util .ArrayList ;
39
+ import java .util .Arrays ;
39
40
import java .util .Base64 ;
40
41
import java .util .HashMap ;
41
42
import java .util .LinkedHashMap ;
42
43
import java .util .List ;
43
44
import java .util .Map ;
44
45
45
46
import static io .cucumber .core .exception .ExceptionUtils .printStackTrace ;
47
+ import static java .util .Collections .singletonList ;
46
48
import static java .util .Locale .ROOT ;
47
49
import static java .util .stream .Collectors .toList ;
48
50
@@ -140,16 +142,7 @@ private void handleTestStepFinished(TestStepFinished event) {
140
142
private void finishReport (TestRunFinished event ) {
141
143
Throwable exception = event .getResult ().getError ();
142
144
if (exception != null ) {
143
- Map <String , Object > feature = new LinkedHashMap <>();
144
- feature .put ("description" , "Test run failed" );
145
- Map <String , Object > elements = new LinkedHashMap <>();
146
- feature .put ("elements" , elements );
147
- elements .put ("description" , "There were errors during the execution" );
148
- Map <String , Object > result = new LinkedHashMap <>();
149
- elements .put ("result" , result );
150
- result .put ("error_message" , exception .getMessage ());
151
- result .put ("status" , "failed" );
152
- featureMaps .add (feature );
145
+ featureMaps .add (createDummyFeatureForFailure (event ));
153
146
}
154
147
155
148
gson .toJson (featureMaps , out );
@@ -160,6 +153,69 @@ private void finishReport(TestRunFinished event) {
160
153
}
161
154
}
162
155
156
+ private Map <String , Object > createDummyFeatureForFailure (TestRunFinished event ) {
157
+ Throwable exception = event .getResult ().getError ();
158
+
159
+ Map <String , Object > feature = new LinkedHashMap <>();
160
+ feature .put ("line" , 1 );
161
+ {
162
+ Map <String , Object > scenario = new LinkedHashMap <>();
163
+ feature .put ("elements" , singletonList (scenario ));
164
+
165
+ scenario .put ("start_timestamp" , getDateTimeFromTimeStamp (event .getInstant ()));
166
+ scenario .put ("line" , 2 );
167
+ scenario .put ("name" , "Could not execute Cucumber" );
168
+ scenario .put ("description" , "" );
169
+ scenario .put ("id" , "failure;could-not-execute-cucumber" );
170
+ scenario .put ("type" , "scenario" );
171
+ scenario .put ("keyword" , "Scenario" );
172
+
173
+ Map <String , Object > when = new LinkedHashMap <>();
174
+ Map <String , Object > then = new LinkedHashMap <>();
175
+ scenario .put ("steps" , Arrays .asList (when , then ));
176
+ {
177
+
178
+ {
179
+ Map <String , Object > whenResult = new LinkedHashMap <>();
180
+ when .put ("result" , whenResult );
181
+ whenResult .put ("duration" , 0 );
182
+ whenResult .put ("status" , "passed" );
183
+ }
184
+ when .put ("line" , 3 );
185
+ when .put ("name" , "Cucumber could not execute" );
186
+ Map <String , Object > whenMatch = new LinkedHashMap <>();
187
+ when .put ("match" , whenMatch );
188
+ whenMatch .put ("arguments" , new ArrayList <>());
189
+ whenMatch .put ("location" , "io.cucumber.core.Failure.cucumber_could_not_execute()" );
190
+ when .put ("keyword" , "When " );
191
+
192
+ {
193
+ Map <String , Object > thenResult = new LinkedHashMap <>();
194
+ then .put ("result" , thenResult );
195
+ thenResult .put ("duration" , 0 );
196
+ thenResult .put ("error_message" , exception .getMessage ());
197
+ thenResult .put ("status" , "failed" );
198
+ }
199
+ then .put ("line" , 4 );
200
+ then .put ("name" , "Cucumber will report this error:" );
201
+ Map <String , Object > thenMatch = new LinkedHashMap <>();
202
+ then .put ("match" , thenMatch );
203
+ thenMatch .put ("arguments" , new ArrayList <>());
204
+ thenMatch .put ("location" , "io.cucumber.core.Failure.cucumber_reports_this_error()" );
205
+ then .put ("keyword" , "Then " );
206
+ }
207
+
208
+ feature .put ("name" , "Test run failed" );
209
+ feature .put ("description" , "There were errors during the execution" );
210
+ feature .put ("id" , "failure" );
211
+ feature .put ("keyword" , "Feature" );
212
+ feature .put ("uri" , "classpath:io/cucumber/core/failure.feature" );
213
+ feature .put ("tags" , new ArrayList <>());
214
+ }
215
+
216
+ return feature ;
217
+ }
218
+
163
219
private Map <String , Object > createFeatureMap (TestCase testCase ) {
164
220
Map <String , Object > featureMap = new HashMap <>();
165
221
featureMap .put ("uri" , TestSourcesModel .relativize (testCase .getUri ()));
0 commit comments