Danesh
Danesh

Reputation: 45

How to run test cases in parallel?

I have one @Test method and I am getting the Test case names from @Dataprovider. I need to run the test cases in parallel:

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

If I want to run the test cases in parallel i.e if I want to execute " Developer Team lead", "QA", "Business Analyst", "DevOps Eng", "PMO" in parallel what should I do?

5 browsers - Each running different test cases.

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 -->

Upvotes: 2

Views: 1192

Answers (2)

user861594
user861594

Reputation: 5908

In order to run data-driven test in parallel, you need to specify parallel=true in @DataProvider. For instance:

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

To specify thread count used by data-driven test, you can specify data-provider-thread-count (defaults to 10). For example:

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

NOTE: To set parallel behavior dynamically for data driven test outside code, you can use QAF-TestNG extension where you can set behavior using global.datadriven.parallel and <test-case>.parallel properties for data-provider.

Upvotes: 1

C. Peck
C. Peck

Reputation: 3717

Well for one thing pubic is not a scope :)--you've also got some more incorrect syntax in there. The space after your the Object in your dataprovider shouldn't be there, the function signature should be

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

Next, the argument in your TestExecution method is defined incorrectly.

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

Finally, you've got to capitalize the 'p' in DataProvider whenever you use it. So that leaves us with

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

At this point I'm not sure what problem(s) remain(s). Is this something like what you were looking for? Let me know if this does or doesn't help.

Upvotes: 0

Related Questions