如何在NUnit的GUI亚军设置单元状态?我试图运行与华廷单个NUnit测试和我收到消息:

  

MyNamespace.LoginTests.CanLogin:结果   System.Threading.ThreadStateException:本CurrentThread需要有它的ApartmentState设置为ApartmentState.STA能够自动的Internet Explorer

有帮助吗?

解决方案

您需要一些配置添加到您的程序集的app.config文件(如果你没有一次,创建一个新的)告诉NUnit的为STA运行:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
    <configSections>
        <sectionGroup name="NUnit">
            <section name="TestRunner" 
                     type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
    </configSections>

    <NUnit>
        <TestRunner>
            <add key="ApartmentState" value="STA" />
        </TestRunner>
    </NUnit>
</configuration>

原源

其他提示

使用Nunit 2.5开始,使用 RequiresSTA 属性,在测试。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top