Specflow AfterFeature not working once a test fails on Assert within a scenario
I have this bunch of scenarios within a feature file and I do something like resetting my organisation job reference number back to the state I met it before my feature file was run. My major problem is that, if the last test in the feature file fails on Assert, then my program does not execute the code in my after feature block. I think irrespective of the faith of the test, after feature should always run, could this be a bug in specflow after feature.
I will appreciate all your feed backs, thanks in advance guys.
So basically you say that the AfterFeature hook is not executed after a failing scenario? Which SpecFlow version you use?
I have the latest version of specflow (2.1.0) and thanks for your interest in this matter, I really need all the help I can get, so I can get to the bottom of this problem. Cheers.
@sirlukman The latest version is 2.2 and not 2.1. So what are you using really? Please have a look in your package.config.
@SabotageAndi Please see above, as I am pretty sure I am using specflow version 2.1.0 and Visual Studio didnt give me to option to update 2.2, as 2.1.0 is what I have as the latest stable version.
Could the issue I am having be down to not having version 2.2 ???
@sirlukman You have a custom feed selected in your package source (top right corner of the "manage packages for solution"- tab). Please change that to nuget.org. There we publish our packages.
I have the same issue with [AfterScenario] My test is failed on Nunit assert, but code in AfterScenario method isn't executing. I guess the reason is that I'm running bunch of tests
-SpecFlow 3.1.74 -Nunit 3.12.0
I also have the same issue with [AfterScenario]. When my test fails on the assert, then I reach the breakpoint in my AfterScenario, but the steps I call from there (with method When()) is not executed.
- SpecFlow: 3.1.86
- MsTest 2.1.0
Same for me. If an assert fails in a test, Specflow methods in [AfterScenario] are not executed. :( Please have a look.
Are you handling your exceptions? From the documentation on hooks:
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.
That would be another scenario. In my scenario, the exception occurs in the test run and not in the AfterScenario.
I need some code to always run even if the test fails, This is because there is very important cleanup to do.
If I follow the advice here and catch the exception, then the test won't fail because Nunit.Assert works by raising an exception.
I need the test to fail and then AfterScenario to run to do the cleanup. I'm also open to another way of doing the cleanup.
We call through to a native library which requires stopping and cleaning up, if we don't clean it up then it will segfault, that segfault will end the process, and because the process was ended SpecFlow doesn't print anything (logs are delayed until the test run finished). So you are completely in the dark with no idea what failed.
I tried to install .net 6 following the instructions on https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-6.0.100-preview.3-linux-x64-binaries
However it didn't work, the version is still .net 5 instead of .net 6
daniel@WS4320:~/Downloads$ mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-6.0.100-preview.3.21202.5-linux-x64.tar.gz -C $HOME/dotnet
daniel@WS4320:~/Downloads$ export DOTNET_ROOT=$HOME/dotnet
daniel@WS4320:~/Downloads$ export PATH=$PATH:$HOME/dotnet
daniel@WS4320:~/Downloads$ dotnet --version
5.0.203
daniel@WS4320:~/Downloads$
@trampster SpecFlow doesn't yet support .NET 6. We will have a look at this in summer.
About your hooks problem. This issue is about that if you have an exception in a hook that the other hooks aren't executed. What you describe looks for me you are doing in a step. In that case the AfterScenario hooks are always executed. If needed you can adjust with the Order parameter in which order the hooks are executed.
What's the status on this issue? Experiencing the same as @dguidali
If an assert fails in a test, Specflow methods in [AfterScenario] are not executed. :(
What's the status on this issue? Experiencing the same as @dguidali
If an assert fails in a test, Specflow methods in [AfterScenario] are not executed. :(
Actually, scratch that. the [AfterFeature] hook works as expected. I had an error in the actual code being executed below the hook, which silently failed.