-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Core] Add Before and AfterStep hooks #1323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
783828d
Adding AfterStep Feature
89a4c90
add tests for AfterStep
f870014
Adding some more tests and refactoring
442a036
fix JSON formatter and add test to validate afterstep
b98656b
Skipping AfterStep in case step fails or is skipped
5528374
Some code refactoring as per review comments
e0f3980
Updating json formatter to be in sync with ruby implementation for af…
f3c908c
Run after step hook until the next test step from a gherkin step
brasmusson 3ae1cff
Represent AfterHookSteps as substeps of a PickleTestStep
mpkorstanje 1da5039
Extract Step and HookSteps from TestStep
mpkorstanje f926057
Make UNDEFINED less severe then AMBIGUOUS
mpkorstanje 3be655e
Treat before and after hooks like hooks rather then unskipable steps
mpkorstanje 50ef0bf
Hide step implementation details from public api
mpkorstanje 423b961
Hide cucumber.runtime.arguments from the public api
mpkorstanje 75b59bc
Add before step hook
mpkorstanje c7b1cfd
Add lambda before and after step hooks
mpkorstanje 44d4f4f
Use concrete types in runner implementation
mpkorstanje 189aea4
Move getDefinitionArgument down to TestStep
mpkorstanje f6b96da
Update JSONFormatter to include BeforeStep
5fa4360
Add javadoc to steps and events
mpkorstanje 5742014
Add javadoc to TestStep.get*Argument
mpkorstanje a2ffa0f
Nested If..else -> switch
34c11e9
AfterStep should be skipped if BeforeStep fails
c1ef976
Rename TestStep to PickleTestStep, HookStep to TestStep, Step to Test…
mpkorstanje e55c769
Rename TestSteps
mpkorstanje 7e3d10d
Always invoke after step hooks when before step hooks have been invoked
mpkorstanje 4cae4bf
Restore test step methods as deprecated methods
mpkorstanje 5266c0e
Remove unused and unsupported methods from internal api
mpkorstanje 6bce153
Use Step, PickleStep and Hook naming convention
mpkorstanje 26a30d8
Tighten accessibility
mpkorstanje 373f729
Merge branch 'master' of github.com:cucumber/cucumber-jvm into featur…
mpkorstanje e632250
Merge branch 'master' into feature_afterstep
mpkorstanje 92e4fa6
[pom] Update the version of the cucumber-html dependency
brasmusson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
package cucumber.runner; | ||
|
||
import cucumber.api.HookType; | ||
import cucumber.api.Result; | ||
import cucumber.api.Scenario; | ||
import cucumber.api.TestStep; | ||
import cucumber.runtime.DefinitionMatch; | ||
import cucumber.runtime.StepDefinitionMatch; | ||
import gherkin.pickles.Argument; | ||
import gherkin.pickles.PickleStep; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static cucumber.api.Result.SEVERITY; | ||
import static java.util.Collections.max; | ||
|
||
public class PickleTestStep extends TestStep { | ||
private String uri; | ||
private PickleStep step; | ||
private final String uri; | ||
private final PickleStep step; | ||
private final List<TestStep> afterStepHooks; | ||
|
||
public PickleTestStep(String uri, PickleStep step, DefinitionMatch definitionMatch) { | ||
this(uri, step, Collections.<TestStep>emptyList(), definitionMatch); | ||
} | ||
|
||
public PickleTestStep(String uri, PickleStep step, List<TestStep> afterStepHooks, DefinitionMatch definitionMatch) { | ||
super(definitionMatch); | ||
this.uri = uri; | ||
this.step = step; | ||
this.afterStepHooks = afterStepHooks; | ||
} | ||
|
||
@Override | ||
public Result run(EventBus bus, String language, Scenario scenario, boolean skipSteps) { | ||
List<Result> results = new ArrayList<Result>(); | ||
|
||
results.add(super.run(bus, language, scenario, skipSteps)); | ||
|
||
for(TestStep after : afterStepHooks){ | ||
results.add(after.run(bus, language, scenario, skipSteps)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method call should also accept param |
||
} | ||
|
||
return max(results, SEVERITY); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isHook() { | ||
return false; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/src/main/java/cucumber/runner/UnskipableHookStep.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cucumber.runner; | ||
|
||
import cucumber.api.HookType; | ||
import cucumber.api.Result; | ||
import cucumber.api.Result.Type; | ||
import cucumber.api.Scenario; | ||
import cucumber.api.TestCase.SkipStatus; | ||
import cucumber.runtime.DefinitionMatch; | ||
|
||
public class UnskipableHookStep extends HookStep { | ||
|
||
public UnskipableHookStep(HookType hookType, DefinitionMatch definitionMatch) { | ||
super(hookType, definitionMatch); | ||
} | ||
|
||
@Override | ||
protected Type executeStep(String language, Scenario scenario, boolean skipSteps) throws Throwable { | ||
definitionMatch.runStep(language, scenario); | ||
return Result.Type.PASSED; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ambiguous
andFailed
both unconditionally make the exit code non-zero, butUndefined
does not, soUndefined
must be less severe thanAmbiguous
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right.