2009-10-06 151 views
1

當我嘗試運行華廷測試槽NUnit的IDE中,我得到錯誤信息:使用Nunit錯誤運行WatiN測試?

ConsoleApplication1.Tests.CanBrowseToMicrosoft: System.Threading.ThreadStateException:本CurrentThread需要有它的ApartmentState設置爲ApartmentState.STA能夠自動化Internet Explorer。

我創建了一個名爲ConsoleApplication1.exe.config應用程序配置文件,該文件是如下:

<?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> 

我班Tests.cs低於:

[TestFixture] 
public class Tests 
{ 
    [Test] 
    public void CanBrowseToMicrosoft() 
    { 
     using (var browser = new IE()) 
     { 
      browser.GoTo("http://www.microsoft.com/"); 
      Assert.That("Microsoft Corporation", Is.EqualTo(browser.Title)); 
     } 
    } 
} 

難道我做錯了什麼?

我遇到的另一個問題是,如何讓NUnit測試結果顯示在vs2008 ide中,而不必運行NUnit Gui?

回答

1

我想通了,因爲我正在加載一個名爲Tests.nunit的NUnit項目,我需要調用應用程序配置文件Tests.config。在這個變化之後,它運行良好。

1

有一個cleaner way來解決您的STAThread要求的問題,但它需要NUnit 2.5。

另外,你有沒有試過TestDriven.Net從Visual Studio運行單元測試?