As a follow-up to my recent post on my Winforms Automation Extensisons post, I realized that I forgot to mention a very important detail.
In many cases, WinForms require to be executed in a Single Threaded Apartment (STA). I write all of my tests in the TestDriven.NET test runner, which runs in the STA by default, but NUnit does not. Resharper also uses the NUnit test runner, so it also runs in MTA by default.
To tell NUnit to run in the STA (and therefore, Resharper), you need to add some data to your app.config file. If you do not already have one, create a file in your test assembly called app.config. Add the following XML:
<?xml version="1.0" encoding="utf-8" ?>Presto! Tests will run in the STA from now on.
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
1 comments:
Came across this post on Google. It gave me exactly what I was looking for.
I knew almost all of the answer about make Resharper run tests as STA, I just couldn't find the exact syntax. Even the JetBrains site didn't seem to have it.
Thanks.
Post a Comment