Visual studio 2010 通过MSTest设置使用WatIn的单元状态
我在中遇到以下错误: CurrentThread需要将其ApartmentState设置为ApartmentState.STA才能自动执行Internet Explorer 使用以下代码:Visual studio 2010 通过MSTest设置使用WatIn的单元状态,visual-studio-2010,nunit,mstest,watin,webtest,Visual Studio 2010,Nunit,Mstest,Watin,Webtest,我在中遇到以下错误: CurrentThread需要将其ApartmentState设置为ApartmentState.STA才能自动执行Internet Explorer 使用以下代码: [TestClass] public class UnitTest1 { [AssemblyInitialize] public static void AssemblySetup(TestContext context) { } [Tes
[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中使用WatIn有不同的方法吗?您可能需要相应地调整配置,下面应该给您一些提示
<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>
考虑更新代码以使用NUnit 2.5 with attribute。请尝试以下方法:
[STAThread]
static void Main(string[] args)
{
}
这是正确的。实际上,我使用的是resharper测试运行程序,它需要与Nunit测试运行程序相同的配置设置。@japrram:是否应该更新问号以列出Nunit而不是mstest?