1

After updating our solution from SpecFlow1.9 to 2.0 and NUnit2.6.4 to 3.2.1 we get a SpecFlowException when the SpecFlow tests are executed with NCrunch

TechTalk.SpecFlow.SpecFlowException : The ScenarioContext.Current static accessor cannot
 be used in multi-threaded execution. Try injecting the scenario context to the binding
 class. See http://go.specflow.org/doc-multithreaded for details.
 at TechTalk.SpecFlow.ScenarioContext.get_Current()

The solution the link http://go.specflow.org/doc-multithreaded in the exception text suggests only works when you use the build-in mini IoC of SpecFlow. However, we use NInject as IoC in our SpecFlow tests. Just wrapping the static field ScenarionContext.Current in a class and registering that class in a singleton context of course just moves the problem to another place.

Does anybody knows how to inject the ScenarionContext when NInject is used instead of the build-in IoC of SpecFlow?

Dariusz Woźniak
  • 9,640
  • 6
  • 60
  • 73
Erik Stroeken
  • 519
  • 4
  • 16
  • Probably related to [this issue](https://github.com/techtalk/SpecFlow/issues/638) – Sam Holder Jun 17 '16 at 09:03
  • Also it might be useful to give some example of how you are using your own IoC, as Specflow will be using its IoC for the tests regardless of what you are using for build the system under test. – Sam Holder Jun 17 '16 at 09:05

1 Answers1

1

SpecFlow now supports other containers via plugins for each container. Only one container can be used as it is injected into SpecFlows container. So if you use the Ninject plugin, then you can only use the Ninject plugin.

Unfortunately the developer who created the Ninject plugin did not publish it to NuGet so you'll have to build it yourself.

https://github.com/MattMcKinney/SpecFlow.Ninject

And you might want to ask him which license his plugin is using.