2010-12-13 15 views
1

我收到以下錯誤:設置單元狀態使用華廷與MSTest的

的CurrentThread需要有它的ApartmentState設置爲ApartmentState.STA能夠自動的Internet Explorer。

用下面的代碼:

[TestClass] 
    public class UnitTest1 
    { 

    [AssemblyInitialize] 
    public static void AssemblySetup(TestContext context) 
    { 

    } 

    [TestMethod] 
    [HostType("ASP.NET")] 
    [AspNetDevelopmentServerHost("C:\\SomePath", "/")] 
    [UrlToTest("http://localhost/HomeView.aspx")] 
    public void TestMethod1() 
    { 
     using(IE ie = new IE("http://localhost/HomeView.aspx",true)) 
     { 
      ie.TextField(Find.ById("MainContent_txtDLNumber")).TypeText("a235801945550"); 
     } 
    } 
} 

是否有使用華廷與MSTest的一種不同的方法?

回答

0

你可能會需要相應地調整你的配置,下面應該給你一個線索

<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

這是正確的。實際上,我使用的是需要與Nunit測試運行器相同的配置設置的resharper測試運行器。 – jparram 2010-12-29 17:31:07

+1

@japrram:問題標籤應該更新爲列出nunit而不是mstest? – GregC 2011-04-28 05:36:54

0

試試這個:

[STAThread] 
static void Main(string[] args) 
{ 
}