NUnit、WatiN SpecFlow 和 STA 线程错误
当我尝试运行 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显示!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或程序集级别使用新的 RequiresSTAAttribute
如果您已安装 nunit 2.5+,请在类TestFixture、RequiresSTA]
。 (在 Assemblyinfo.cs)
使用 NUnit.Framework;
...
[程序集:需要STA]
不需要配置文件。
检查此链接以获取更多信息:
http://www.nunit.org/index.php?p=requiresSTA&r=2.5< /a>
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
缺少
。无论如何,当我使用 WatiN + Nunit + MSVS 时,我在测试项目中有这样的配置:
is missing.
Anyway when I was using WatiN + Nunit + MSVS, I had this configuration in my testing project: