0
votes

I have a solution in Visual Studio 2010 that includes a test project that uses WatiN. It also has a test project with unit tests. Both use NUnit as the framework. I use Gallio to run/debug the tests.

I'm trying out Visual Studio 2012. My project builds fine. I can use the NUnit GUI to run both sets of tests. The Test Explorer lists all tests (unit and UI). I can run/debug the unit tests from within Visual Studio.

When I run the UI tests from within Visual Studio 2012 I get an error:

The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

The error occurs on the following line in my TestFixtureSetup function:

browser = new IE(...);

I've Googled the error and seen plenty of suggestions about adding lines to the app.config. The odd thing is that I already have those lines.

<sectionGroup name="NUnit">
  <section name="TestRunner" 
           type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>

...

<NUnit>
  <TestRunner>
    <!-- Valid values are STA or MTA (Others are ignored) -->
    <add key="ApartmentState" value="STA" />
  </TestRunner>
</NUnit>

Has anyone gotten WatiN working with the Test Explorer in Visual Studio 2012? Any suggestions for getting it to work? Are there known compatibility issues?

I also tried installing Gallio with the RC and it broke some things that required a bit of effort to fix. I would prefer to use the integrated Test Explorer.

1

1 Answers

2
votes

Found a solution here.

I added the following to my AssemblyInfo.cs file:

[assembly: RequiresSTA]

Still outstanding is why doesn't the test runner see the STA settings in the app.config?