Pardon me if this sounds naive (I am very new to SpecFlow), but what I want to do is this:
I have an application context that handles all of the initializations needed to run my wpf application, which is actually used in my application when it runs. In this application context, I have a method to initialize my app for testing, which basically does everything except show the application window. What I am looking to do is simply instantiate this application context in the context of my specflow test because it would give me access to all of my view models in my test steps. But to do so, I need to make the thread that the specflow test steps are running on have a STA ApartmentState because my application is constructing a number of wpf controls, just not displaying them.
I am using SpecFlow 2.1.0 with NUnit 3.4.1 and executing the tests in Visual Studio 2015.
I have tried a multitude of things, including putting the following in the App.config file:
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
And instantiating my ApplicationContext on a background thread with the STA ApartmentState added to it, but none of them have worked.
The App.config file flat out did not work, I got the same STA exception as before.
Instantiating my ApplicationContext just created another thread separate from the thread the test was running on, so my test steps started executing before my application context was even instantiated. I even tried awaiting the instantiation in a [BeforeTestRun] method but the test steps still started executing prematurely.
Does anyone have any experience doing this? Am I going about this the wrong way? I would rather not create an entirely different application context just for testing.
Any input you have would be helpful! Thank you!