NUnit的,华廷SpecFlow和STA线程错误
问题描述:
我收到以下异常,当我尝试运行SpecFlow测试:NUnit的,华廷SpecFlow和STA线程错误
的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显示!
答
下面的代码
丢失。
反正我是用华廷+ 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>
答
如果您已经安装了NUnit的2.5+,使用新的RequiresSTAAttribute在类
TestFixture,RequiresSTA]
或装配级别。 (at Assemblyinfo.cs)
using NUnit.Framework;
...
[装配:RequiresSTA]
无需配置文件。 检查此链接了解更多信息: http://www.nunit.org/index.php?p=requiresSTA&r=2.5
哦是的,我有这个代码由于某种原因*没有显示它。即使使用XML配置,我也遇到了同样的错误! – azamsharp 2011-03-09 14:09:50
似乎只有在nUnit GUI模式下运行测试时才会出现错误。我只用了TestDriven.NEt,它的功能就像一个魅力!谢谢! – azamsharp 2011-03-09 14:44:22