【问题标题】:How do I get Nunit to run selenium tests against different servers?如何让 Nunit 对不同的服务器运行 selenium 测试?
【发布时间】:2010-05-20 22:34:57
【问题描述】:

我有一个 Nunit 测试,它使用 selenium RC 对我们的 UI 运行测试。我想针对 2 个不同的服务器运行测试,这意味着使用 2 个不同的服务器调用 selenium.open()。但是,我不想拥有 2 个不同的 Nunit 测试套件,它们做同样的事情,但针对不同的服务器。我需要一种将参数从 Nant 或 Nunit 驱动程序传递到特定服务器的方法来进行测试。

有没有办法做到这一点?

【问题讨论】:

  • 我想到了一个办法,谁能给我更好的解决方案?基本上,对于不同的服务器,我有不同版本的 app.config 文件。在 Nant 构建脚本中,我将文件的不同版本复制到 app.config(例如 app.test.config --> app.config)。在 app.config 中,我有不同的基本 Url 在 nunit 测试中用作 appsetting。

标签: nunit selenium nant


【解决方案1】:

如果您希望对两台服务器运行相同的测试,最新版本的 NUnit 支持带参数的测试。您可以像这样在测试中包含服务器参数:

[TestFixture]
public class MyTestFixture
{
    public string[] Servers = new string[] { "server1.address", "server2.address" };

    [Test]
    public void SomeTest([ValueSource("Servers")] server)
    {
        ISelenium selenium = new DefaultSelenium(server, 4444, "*firefox", "http://localhost");
        //rest of test
    }
}

当 NUnit 执行时,该测试将运行两次:一次使用“server1.address”参数,一次使用“server2.address”参数。您可以在此处阅读 ValueSource 测试:http://www.nunit.org/index.php?p=valueSource&r=2.5.5

【讨论】:

    猜你喜欢
    • 2018-08-30
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    相关资源
    最近更新 更多