4242import java .util .HashMap ;
4343import java .util .Optional ;
4444import java .util .UUID ;
45+ import java .util .function .Consumer ;
4546import java .util .stream .Collectors ;
4647import java .util .stream .IntStream ;
4748
@@ -151,8 +152,7 @@ private void handleTestStepStarted(final TestStepStarted event) {
151152 cucumberSourceUtils .getKeywordFromSource (currentFeatureFile , event .testStep .getStepLine ())
152153 ).orElse ("UNDEFINED" );
153154
154- final StepResult stepResult = new StepResult ();
155- stepResult
155+ final StepResult stepResult = new StepResult ()
156156 .withName (String .format ("%s %s" , stepKeyword , event .testStep .getPickleStep ().getText ()))
157157 .withStart (System .currentTimeMillis ());
158158
@@ -162,6 +162,12 @@ private void handleTestStepStarted(final TestStepStarted event) {
162162 .filter (argument -> argument instanceof PickleTable )
163163 .findFirst ()
164164 .ifPresent (table -> createDataTableAttachment ((PickleTable ) table ));
165+ } else if (event .testStep .isHook () && event .testStep instanceof UnskipableStep ) {
166+ final StepResult stepResult = new StepResult ()
167+ .withName (event .testStep .getHookType ().toString ())
168+ .withStart (System .currentTimeMillis ());
169+
170+ lifecycle .startStep (getTestCaseUuid (currentTestCase ), getHookStepUuid (event .testStep ), stepResult );
165171 }
166172 }
167173
@@ -186,6 +192,11 @@ private String getStepUuid(final TestStep step) {
186192 + step .getPickleStep ().getText () + step .getStepLine ();
187193 }
188194
195+ private String getHookStepUuid (final TestStep step ) {
196+ return currentFeature .getName () + getTestCaseUuid (currentTestCase )
197+ + step .getHookType ().toString () + step .getCodeLocation ();
198+ }
199+
189200 private String getHistoryId (final TestCase testCase ) {
190201 final String testCaseLocation = testCase .getUri () + ":" + testCase .getLine ();
191202 return Utils .md5 (testCaseLocation );
@@ -239,16 +250,11 @@ private void createDataTableAttachment(final PickleTable pickleTable) {
239250 }
240251
241252 private void handleHookStep (final TestStepFinished event ) {
242- final String uuid = UUID .randomUUID ().toString ();
243- final StepResult stepResult = new StepResult ()
244- .withName (event .testStep .getHookType ().toString ())
245- .withStatus (translateTestCaseStatus (event .result ))
246- .withStart (System .currentTimeMillis () - event .result .getDuration ())
247- .withStop (System .currentTimeMillis ());
248-
249- if (!Status .PASSED .equals (stepResult .getStatus ())) {
253+ final String uuid = getHookStepUuid (event .testStep );
254+ Consumer <StepResult > stepResult = result -> result .withStatus (translateTestCaseStatus (event .result ));
255+
256+ if (!Status .PASSED .equals (translateTestCaseStatus (event .result ))) {
250257 final StatusDetails statusDetails = ResultsUtils .getStatusDetails (event .result .getError ()).get ();
251- stepResult .withStatusDetails (statusDetails );
252258 if (event .testStep .getHookType () == HookType .Before ) {
253259 final TagParser tagParser = new TagParser (currentFeature , currentTestCase );
254260 statusDetails
@@ -260,9 +266,12 @@ private void handleHookStep(final TestStepFinished event) {
260266 scenarioResult .withStatus (Status .SKIPPED )
261267 .withStatusDetails (statusDetails ));
262268 }
269+ stepResult = result -> result
270+ .withStatus (translateTestCaseStatus (event .result ))
271+ .withStatusDetails (statusDetails );
263272 }
264273
265- lifecycle .startStep ( getTestCaseUuid ( currentTestCase ), uuid , stepResult );
274+ lifecycle .updateStep ( uuid , stepResult );
266275 lifecycle .stopStep (uuid );
267276 }
268277
0 commit comments