2

我有一种@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 个浏览器——每个都运行不同的测试用例。

测试NG 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 -->
4

2 回答 2

1

为了并行运行数据驱动测试,您需要parallel=true@DataProvider. 例如:

@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 扩展,您可以在其中使用data-providerglobal.datadriven.parallel和属性设置行为。<test-case>.parallel

于 2019-03-16T23:33:49.473 回答
0

好吧,一方面pubic不是范围:)--那里还有一些更不正确的语法。您的 dataprovider 后面的空格Object不应该在那里,函数签名应该是

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"} };
}

在这一点上,我不确定还有什么问题。这和你要找的一样吗?让我知道这是否有帮助。

于 2019-03-16T22:57:28.630 回答