2 回答
TA贡献1776条经验 获得超12个赞
解决方案基本上取决于您使用的测试框架。NUnit 从 3.7 版本开始支持并行测试执行。演示该想法的示例如下
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);
}
}
TA贡献1775条经验 获得超8个赞
我使用您的代码示例对其进行了调整,但问题是它打开了 5 个 Chrome 实例,但它仅适用于一个实例,而不是同时适用于其中的 5 个实例
[TestCaseSource(nameof(Cases)), Parallelizable(ParallelScope.Children)]
public void ItShouldSleep(TimeSpan t)
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-notifications");
Driver = new ChromeDriver(@"C:\Users\slaouadi\source\repos\UnitTestProject1", options);
string baseUrl = "https://www.google.com/";
Driver.Navigate().GoToUrl(baseUrl);
Driver.FindElement(By.Id("lst-ib")).SendKeys("IT WORKED FINE");
}
- 2 回答
- 0 关注
- 158 浏览
添加回答
举报