简体   繁体   English

如何在并行执行中将相同的测试运行 X 次?

[英]How can I run the same test for X times in parallel execution?

I have a simple test我有一个简单的测试

@Test
public void searchInGoogle() {
    final String searchKey = "TestNG";
    System.out.println("Search " + searchKey + " in google");
    driver.navigate().to("http://www.google.com");
    WebElement element = driver.findElement(By.name("q"));
    System.out.println("Enter " + searchKey);
    element.sendKeys(searchKey);
    System.out.println("submit");
    element.submit();
    System.out.println("Got " + searchKey + " results");
}

I want to run it 10 times in parallel, Meaning 10 chrome windows will open parallel and execute the same test.我想并行运行它 10 次,这意味着 10 个 chrome 窗口将并行打开并执行相同的测试。

Please help , I've seen things similar but not exactly this.请帮忙,我见过类似的东西,但不完全是这样。

Thanks !谢谢 !

In JUnit 5 you can use @RepeatedTest to run a single test case multiple times.在 JUnit 5 中,您可以使用@RepeatedTest 多次运行单个测试用例。

Though presently still an experimental feature, you can also specify that tests should be executed in parallel , by setting the junit.jupiter.execution.parallel.enabled to true as part of your JUnit 5 configuration settings .虽然目前仍是一个实验性功能,但您也可以指定应该并行执行测试,方法是将junit.jupiter.execution.parallel.enabled设置为 true 作为JUnit 5 配置设置的一部分

Your code would then look as follows:您的代码将如下所示:

@Execution(CONCURRENT)
class GoogleSearchTest {

  import ...

  @RepeatedTest(10)
  public void searchInGoogle() {
    ...
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Maven测试运行输出中获取并行执行标识符 - How to get parallel execution identifier in Maven test run output WebDriver:如何使用同一浏览器(Firefox)处理并行测试执行? - WebDriver: How to deal with parallel test execution using the same browser (Firefox)? 如何在循环中多次运行多个测试方法 - How can I run multiple test methods multiple times in a loop 如何使用 BeforeTest 执行多次运行 TestNG 测试? - How to run TestNG test several times with BeforeTest execution? 如何多次使用相同的测试数据多次运行同一JUnit测试? - How do I run the same JUnit test multiple times with different test data each time? 如何使用相同的数据提供程序并行运行硒测试 - How to run selenium test in parallel using the same dataprovider 如何在多台服务器上的IE中并行运行TestNG / Selenium测试套件? - How can I run a TestNG/Selenium test suite in IE on multiple servers in parallel? 如何在Java Stream的单个步骤中使用并行执行 - How can I use parallel execution on a single step of a Java Stream 如何使用XML文件使用testNG多次运行测试? - How can i run a Test multiple times using testNG using XML file? 如何使用jsp运行测试用例(用junit 3.x和4.x编写)? - How can I run my test cases (which written in junit 3.x and 4.x) using jsp?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM