运行 WatiN 测试时出现 Nunit 错误?

发布于 2024-08-07 01:34:08 字数 1159 浏览 1 评论 0原文

当我尝试通过 NUnit ide 运行 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?

When I try to run a WatIn test trough the NUnit ide, I get the error message:

ConsoleApplication1.Tests.CanBrowseToMicrosoft:
System.Threading.ThreadStateException : The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

I created an application configuration file called ConsoleApplication1.exe.config which is below:

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

My class Tests.cs is below:

[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));
        }
    }
}

Am I doing something wrong?

The other question I had was how do I get the NUnit test results to show up in vs2008 ide instead of having to run the NUnit Gui?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原谅过去的我 2024-08-14 01:34:08

我想通了,因为我正在加载一个名为Tests.nunit的NUnit项目,所以我需要调用应用程序配置文件Tests.config。经过这次更改后,效果很好。

I figured it out, because I was loading an NUnit project called Tests.nunit, I need to call the application configuration file Tests.config. After this change, it worked fine.

绝影如岚 2024-08-14 01:34:08

有一种更干净的方法来解决您的 STAThread 要求问题,但它需要 NUnit 2.5。

另外,您是否尝试过 TestDriven.Net 从 Visual Studio 运行单元测试?

There is a cleaner way to resolve your issue with STAThread requirement, but it requires NUnit 2.5.

Also, have you tried TestDriven.Net to run unit tests from Visual Studio?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文