2011-03-08 30 views
5

我收到以下異常,當我嘗試運行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顯示!

回答

3

下面的代碼

丟失。

反正我是用華廷+ 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> 
+0

哦是的,我有這個代碼由於某種原因StackOverflow沒有顯示它。即使使用XML配置,我也遇到了同樣的錯誤! – azamsharp 2011-03-09 14:09:50

+0

似乎只有在nUnit GUI模式下運行測試時纔會出現錯誤。我只用了TestDriven.NEt,它的功能就像一個魅力!謝謝! – azamsharp 2011-03-09 14:44:22

12

如果您已經安裝了NUnit的2.5+,使用新的RequiresSTAAttribute在類

TestFixture,RequiresSTA]

或裝配級別。 (at Assemblyinfo.cs)

using NUnit.Framework;

...

[裝配:RequiresSTA]

無需配置文件。 檢查此鏈接瞭解更多信息: http://www.nunit.org/index.php?p=requiresSTA&r=2.5