This one came up today and surprised me.  I usually use the ReSharper test runner, but I wanted to try out the new, improved Visual Studio Test Explorer in VS2012.  I have NUnit-based unit and integration tests and SpecFlow/WatiN UI automation tests that use NUnit behind the scenes.

Visual Studio Extensions and Updates

You'll need to install the NUnit Test Adapter so the Visual Studio Test Explorer knows what to do.  You don't need to go back and change attributes, references, etc. to use MSTest.  It can work with NUnit natively once you add this extension under Tools > Extensions and Updates.


Apartment State

Using SpecFlow with NUnit means you have to set your app.config ApartmentState to STA.  This is well documented, but it's one of those things you have to do to get everything working.

    <add key="ApartmentState" value="STA"/>

Making this app.config change is all the ReSharper test runner needs, but the Visual Studio Test Explorer needs a little more help.  You have to set the NUnit attribute

[assembly: RequiresSTA]

in your AssemblyInfo.cs for your test project where your SpecFlow tests live.


Now you should be able to run ALL your solution's tests with the Visual Studio Test Explorer, including the SpecFlow ones!

Visual Studio Test Explorer still needs a lot of work around grouping tests, and Peter Provost says as much in his blog post, but it has come a long way.