NUnit, WatiN SpecFlow and STA Thread Errors
I am getting the following exception when I try to run t开发者_Go百科he 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!
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
The following code
is missing.
Anyway when I was using 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>
精彩评论