【问题标题】:Selenium Grid with parallel testing using C#/NUnit使用 C#/NUnit 进行并行测试的 Selenium Grid
【发布时间】:2009-11-18 16:45:06
【问题描述】:

我有几个用 NUnit 编写的单元测试,它们调用 selenium 命令。我已经设置了 2 个 win2k3 服务器盒,一个正在运行 selenium 网格集线器和 2 个 selenium rc。另一个盒子正在运行 5 个 selenium rc。它们都在集线器上注册为在 Windows 上运行 Firefox(为了简单起见)。在我的单元测试设置方法中,我已将它连接到端口 4444 处的集线器主机名。

运行测试时,它们仅按顺序运行(如预期的那样)。我对 NUnit 的路线图以及他们如何争取并行测试能力进行了大量阅读。在此期间,我看到了很多使用 PNUnit 的建议。然而,这似乎完全违背了 Selenium Grid 的目的。

你们中是否有人使用连接到 Selenium Grid 设置的 C#/NUnit 成功实现了并行测试?如果有,请详细说明。

我完全不知道如何使用 NUnit,因为它现在存在(我使用的是 2.9.3 版)

【问题讨论】:

    标签: c# nunit selenium-grid pnunit


    【解决方案1】:

    不幸的是,NUnit 不能并行运行测试,因此您必须使用另一个运行器来归档使用 Selenium Grid 进行并行测试的所有优势。

    我在 c# 上使用 Gallio runner 进行测试,这里有示例:

    使用并行运行测试的 c# 项目:http://code.google.com/p/design-of-selenium-tests-for-asp-net/

    描述:http://slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html

    Gallio 测试运行器:http://www.gallio.org/

    【讨论】:

    【解决方案2】:

    还有PNUnit,值得一看,我还没试过并行测试。

    【讨论】:

      【解决方案3】:

      NCrunch (http://www.ncrunch.net/) 值得一看 - 它可以选择分布式处理作为构建的一部分,其主要功能之一是并行测试。

      【讨论】:

        【解决方案4】:

        通过将 Selenium Grid 与 .NET 的任务并行库和 DynamicObject 类结合使用,您可以同时在多个 Selenium Grid 节点(多个浏览器)上运行相同的测试。

        http://blog.dmbcllc.com/running-selenium-in-parallel-with-any-net-unit-testing-tool/

        【讨论】:

          【解决方案5】:

          Gallio 今天已经过时了,所以你可以坚持使用 NUnit 解决方案。

          从 3.7 版本开始,NUnit 允许并行运行测试。在此之前,可以在夹具级别执行此操作,但在 3.7+ 中,您甚至可以在一个 TestFixute 中进行测试。请参阅下面的示例以演示如何实现它。

          using NUnit.Framework;
          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Threading;
          
          namespace ConsoleApp1
          {
              [TestFixture]
              public class Dummy
              {
                  static TestCaseData Case(int i)
                      => new TestCaseData(TimeSpan.FromSeconds(2)).SetName($"Case {i}");
          
                  public static IEnumerable<TestCaseData> Cases()
                      => Enumerable.Range(1, 5).Select(Case);
          
                  [TestCaseSource(nameof(Cases)), Parallelizable(ParallelScope.Children)]
                  public void ItShouldSleep(TimeSpan t)
                      => Thread.Sleep(t);
          
          
                  static TestCaseData Case2(int i)
                      => new TestCaseData(TimeSpan.FromSeconds(2)).SetName($"Case2 {i}");
          
                  public static IEnumerable<TestCaseData> Cases2()
                      => Enumerable.Range(1, 5).Select(Case2);
          
                  [TestCaseSource(nameof(Cases2)), Parallelizable(ParallelScope.Children)]
                  public void ItShouldSleep2(TimeSpan t)
                      => Thread.Sleep(t);
              }
          
              [TestFixture()]
              public class Dummy2
              {
                  static TestCaseData Case(int i)
                      => new TestCaseData(TimeSpan.FromSeconds(2)).SetName($"Case {i}");
          
                  public static IEnumerable<TestCaseData> Cases()
                      => Enumerable.Range(1, 5).Select(Case);
          
                  [TestCaseSource(nameof(Cases)), Parallelizable(ParallelScope.Children)]
                  public void ItShouldSleep(TimeSpan t)
                      => Thread.Sleep(t);
              }
          }
          

          【讨论】:

            猜你喜欢
            • 2010-09-17
            • 2012-06-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-04-06
            相关资源
            最近更新 更多