2

Because im changing in my specflow scenario important configuration I would like my specflow scenario to reset the configuration everytime it finish the scenario, even if it fails in the middle. [AfterScenario] do the work only if it didnt fails, but I need something to reset my configuration even if it fails.

Thanks!

Matan
  • 21
  • 2

1 Answers1

3

I would suggest, that you check and if needed reset your configuration at the beginn of the test and not at the end.
So you can ensure that the tests starts with a clean slate. See it as a step in the Arrange- part of your test.

Reason for this is, that not only at a failing test the AfterScenario is not executed. If you debug the test and stop it, it is also not called.

Andreas Willich
  • 5,665
  • 3
  • 15
  • 22
  • 1
    This is generally good advice for your tests, regardless of if they are in specflow or not. – Sam Holder Nov 02 '16 at 12:02
  • Thanks for the good idea but im in organiztion that make a lot of tests and i cant add a check in every test if it needs to restart the configuration, and i dont want that tests that will come after me will get effected because of my test that got failed. You are right that [after scenerio] wont help either if ill stop in debug mode, but mabye you have a solution that can solve the first problem or mabye in the best case both of them? – Matan Nov 02 '16 at 12:06
  • @matan the suggestion was to do the cleanup in a `[BeforeScenario]` (or `[BeforeFeature]`) as well as in the `[AfterScenario]` as then it doesn't matter if the test is stopped, but this sounds like a bug in Specflow as it should call the `[AfterScenario]` even if the test fails. See [this](http://gasparnagy.com/2016/04/specflow-tips-collect-more-information-on-error-part-1/) – Sam Holder Nov 08 '16 at 22:40