Add Step info to @BeforeStep and @AfterStep hooks#3139
Add Step info to @BeforeStep and @AfterStep hooks#3139mpkorstanje merged 13 commits intocucumber:mainfrom
Conversation
Allow @BeforeStep and @afterstep hooks to receive step information (keyword, text, line number) alongside the existing Scenario parameter. New API: ```java @BeforeStep public void beforeStep(Scenario scenario, Step step) { System.out.println("Running: " + step.getKeyword() + step.getText()); System.out.println("At line: " + step.getLine()); } ``` Changes: - Add new io.cucumber.java.Step interface exposing step details - Add StepInfo wrapper class implementing Step interface - Extend HookDefinition with execute(state, step) default method - Update JavaHookDefinition to support 2-parameter step hooks - Pass step info through HookTestStep execution chain - Maintain full backward compatibility with existing hooks Closes cucumber#1805
mpkorstanje
left a comment
There was a problem hiding this comment.
Overall this looks like a decent approach.
-
The
HookTestStep::runmethod is duplicated. I don't think that this is necessary. InTestStep::executeStepit should be possible to pass the step argument and propagate it down toHookDefinition::executeby adding an extra argument toStepDefinitionMatch::runStep. If it goes unused in other places, that is okay. -
io.cucumber.plugin.event.StepArgumentshouldn't be visible to users but I don't know what to request that yet.
|
Don't worry about the Semver check btw. |
- Remove duplicated run method from HookTestStep, use parent's implementation - Pass step argument through TestStep::executeStep and ExecutionMode - Add runStep(state, step) default method to StepDefinitionMatch interface - Make HookDefinition.execute(state) a default no-op and deprecate it - Remove getArgument() from Step interface (StepArgument visibility concern) - Refactor JavaHookDefinition validation to explicitly check hook types - Update tests to match new error message format
|
pushed changes based on the comments, if you could re-review |
mpkorstanje
left a comment
There was a problem hiding this comment.
Please review your own code before asking me for a review.
- These changes came in incredibly fast.
- The changes are as requested in letter, but not in spirit. I find that I'm writing the same comments as I did in my previous review, but for exactly one level higher in the call chain.
- There is a rather obvious blunder in the code that regular refactoring tools wouldn't produce.
Normally I'd give you the benefit of the doubt but I do see several LLM based projects on your profile so I am skeptical that you've done the necessary work to create a correct pull request.
|
I will go through all my changes, one by one, apologies |
- StepDefinitionMatch.runStep() now takes Step parameter directly - ExecutionMode.execute() takes Step parameter - TestStep.run() takes Step parameter - Step flows through: TestStep → ExecutionMode → StepDefinitionMatch → HookDefinition
|
@mpkorstanje i did made some changes but i need your opinion here.. i really dont like the ,null in the step.run, i would prefer overloading but i was concerned you would see it as duplication. What is your preference? Overload the run or the ,null is fine? |
|
I think null values for method arguments and constructors are fine. Especially in internal APIs. Just don't return them. I'm currently working on adding nullability information with Jspecify. So then the compiler will be able to check once that lands. |
|
In this case if you can review once more it would be great. As for the nulluability thats would be super helpful because null pointers in cucumber debuging is a pain.. |
mpkorstanje
left a comment
There was a problem hiding this comment.
Looks better. I'm going too need to take a closer look at the inheritance around TestStep.
mpkorstanje
left a comment
There was a problem hiding this comment.
Using the TestCaseState to keep track of the current active gherkin step analogous to the currently active test step (hooks or steps) the solution simplifies a lot. I've pushed that as a change.
Please do update the cucumber-java/README.md with some documentation. And some tests to verify everything works as expected. The refactoring of the hook definition validation introduced several branches that are not covered. And the feature itself is untested.
|
Added the requested documentation and tests:
Ready for review when you have time. |
Summary
This PR implements the feature requested in #1805 - allowing
@BeforeStepand@AfterStephooks to receive step information (keyword, text, line number) alongside the existingScenarioparameter.New API:
Changes
io.cucumber.java.Stepinterface exposing step detailsStepInfowrapper class implementing theStepinterfaceHookDefinitionwithexecute(state, step)default methodJavaHookDefinitionto support 2-parameter step hooksHookTestStepexecution chainBackward Compatibility
Test plan
Closes #1805