[英]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.