当我尝试运行SpecFlow测试时,我收到以下异常:
CurrentThread需要将它的ApartmentState设置为ApartmentState.STA才能自动化Internet Explorer。
我已经在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>
我正在使用VS 2010并强制我的应用程序以3.5版本运行。
我也在使用nUnit工具的GUI显示!
答案 0 :(得分:12)
如果你已经安装了nunit 2.5+,请在课堂上使用新的The RequiresSTAAttribute
TestFixture,RequiresSTA]
或汇编级别。 (在Assemblyinfo.cs上)
使用NUnit.Framework;
...
[组件:RequiresSTA]
无需配置文件。 查看此链接以获取更多信息: http://www.nunit.org/index.php?p=requiresSTA&r=2.5
答案 1 :(得分:3)
以下代码
缺少。
无论如何,当我使用WatiN + Nunit + MSVS时,我的测试项目中有这个配置:
<?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>