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
Suggestion: Add Option to Run After Hooks Despite Exceptions #978
Comments
@gasparnagy We had in the past a discussion about the topic of exceptions in hooks, but I don't find it anymore. But somehow I have a little aversion against the idea with the additional attribute. Doesn't feel right somehow for me. |
@SabotageAndi - I like your proposed parameter name "ContinueOnError" better than the ones I suggested. Also, at the very least, could the current behavior of after hooks please be documented on the SpecFlow doc pages? The current Hooks page does not indicate that if an exception happens in an after hook, then subsequent after hooks of the same type will not be called. It would be very helpful to make this explicitly stated to avoid confusion. Users could presume either the current behavior or (like I did) that subsequent after hooks would be run despite exceptions. https://github.com/techtalk/SpecFlow/wiki/Hooks |
@AndyLPK247 you are right, this information is missing in the documentation |
I've added a note to the hooks section under "Hook Execution Order". This behaviour applies to both before and after hooks. Here's the change: Note: If a hook throws an unhandled exception, subsequent hooks of the same type are not executed. If you want to ensure that all hooks of the same types are executed, you need to handle your exceptions manually. |
Awesome! Thanks.
…On Tue, Dec 5, 2017 at 5:50 AM, Stephen McCafferty ***@***.*** > wrote:
I've added a note to the hooks section under "Hook Execution Order". This
behaviour applies to both before and after hooks. Here's the change:
Note: If a hook throws an unhandled exception, subsequent hooks of the
same type are not executed. If you want to ensure that all hooks of the
same types are executed, you need to handle your exceptions manually.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#978 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARJ9UtjajuGtk4E63SNBJpS5vDe3tkaiks5s9R_egaJpZM4Q00u8>
.
|
Hi @SabotageAndi , In my case I'm using an attribute "AfterTestRun" and after that running DB Hook (cleaning test data) - is it possible to add some functionality which helps to skip running DB Hook if some of the tests are failed. I've tried to use ScenarioContext.Current but unfortunately it didn't work as this Context saved only latest scenario. |
To make it easier for you all to vote on feature requests and influence our prioritization of them in our backlog, we created in our new support tool a special forum to have a better overview of all of them. We moved this feature request there and you can find it here. Sadly we could not take over the existing votes. So if you are still interested in this feature request, please vote again on the new list. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
It is possible to have multiple after hooks, and the order of execution may be controlled with the Order parameter. However, if an exception is thrown from an after hook method, then no subsequent after hooks of the same type are executed. This is problematic for my team because we do web testing using Selenium WebDriver. We rely upon after hooks to properly clean up our web tests. It is also arguably unintuitive - my original presumption was that after hooks would always be run for safety purposes.
Consider the following example:
If hook #2 throws an exception, then hook #3 is not run.
There are a few workarounds:
What would be really nice is if After hooks had an extra attribute parameter called "AlwaysRun" or "Guaranteed" or something similar that would make the hook run even if previous hooks aborted with exceptions. I could add such a parameter to hook #3 and not need any of the aforementioned workarounds. This sort of solution would be applicable for all after hook types: step, scenario, scenario block, and test run.
The text was updated successfully, but these errors were encountered: