2009-10-06 136 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运行单元测试?