Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit, WatiN SpecFlow and STA Thread Errors

I am getting the following exception when I try to run the SpecFlow test:

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

I have already added the following code in App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="NUnit">
      <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
  </configSections>
  <NUnit>
    <TestRunner>
      <!-- Valid values are STA,MTA. Others ignored. -->
      <add key="ApartmentState" value="STA" />
    </TestRunner>
  </NUnit>
</configuration>

I am using VS 2010 and forcing my app to run as version 3.5.

I am also using the GUI display of nUnit tool!

like image 200
azamsharp Avatar asked Mar 08 '11 22:03

azamsharp


1 Answers

If you have installed nunit 2.5+, use the new The RequiresSTAAttribute at class

TestFixture, RequiresSTA]

or assembly level. (at Assemblyinfo.cs)

using NUnit.Framework;

...

[assembly:RequiresSTA]

No need for config file. Check this link for more info: http://www.nunit.org/index.php?p=requiresSTA&r=2.5

like image 70
mas_oz2k1 Avatar answered Nov 10 '22 00:11

mas_oz2k1