如何运行并行测试用例?

How to run test cases in parallel?

我有一个 @Test 方法,我从 @Dataprovider 获取测试用例名称。我需要 运行 并行测试用例:

@Test(dataprovider="testdataprodivder")
public void TestExecution(String arg 1)
{
/* Read the testcases from dataprovider and execute it*/
}
@Dataprovider(name="testdataprodivder")
public Object [][]Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}

如果我想 运行 并行测试用例 即,如果我想并行执行“Developer Team lead”、"QA"、"Business Analyst"、"DevOps Eng"、"PMO",我应该怎么做?

5 个浏览器 - 每个 运行ning 不同的测试用例。

TestNG XML:

<suite name="Smoke_Test" parallel="methods" thread-count="5"> 
<test verbose="2" name="Test1">
<classes>
  <class name="Packagename.TestName"/>
</classes>
</test> <!-- Default test -->  
</suite> <!-- Default suite -->

好吧,一方面 pubic 不是作用域 :)--您那里还有一些不正确的语法。数据提供者中 Object 之后的 space 不应该存在,函数签名应该是

public Object[][] Execution() throws IOException {
     return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}

接下来,您的 TestExecution 方法中的参数定义不正确。

public void TestExecution(String arg) {
    // Execute your tests
}

最后,无论何时使用 DataProvider 中的 'p' 都必须大写。这样就剩下

@Test(dataProvider="testdataprovider")
public void TestExecution(String arg)
{
/* Read the testcases from dataprovider and execute it*/
}
@DataProvider(name="testdataprovider")
public Object[][] Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}

此时我不确定还有什么问题。这就是您要找的东西吗?让我知道这是否有帮助。

为了运行并行数据驱动测试,您需要在@DataProvider中指定parallel=true。例如:

@Dataprovider(name="testdataprodivder", parallel=true)
public Object [][]Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}

要指定数据驱动测试使用的线程数,您可以指定 data-provider-thread-count(默认为 10)。例如:

<suite name="Smoke_Test" parallel="methods" thread-count="5" data-provider-thread-count="5"> 

注意:要为代码外的数据驱动测试动态设置并行行为,您可以使用QAF-TestNG extension where you can set behavior using global.datadriven.parallel and <test-case>.parallel properties for data-provider.