NUnit, WatiN SpecFlow and STA Thread Errors

I get the following exception when I try to run the SpecFlow test:

In CurrentThread, you need ApartmentState to set InternetStation Automation to ApartmentState.STA.

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 use VS 2010 and make my application run as version 3.5.

I also use the nUnit tool GUI!

+5
source share
2 answers

Following code

missing.

Anyway, when I used WatiN + Nunit + MSVS, I had this configuration in my testing project:

<?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>
+3
source

nunit 2.5+, RequiresSTAAttute

TestFixture, RequiresSTA]

. ( Assemblyinfo.cs)

NUnit.Framework;

...

[: RequiresSTA]

. : http://www.nunit.org/index.php?p=requiresSTA&r=2.5

+12

All Articles