Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestNG parallel Execution with DataProvider

I have a single test which receives data from data provider. I would like this test to run in parallel with different values from data provider .

I tried an approach like :

public class IndependentTest
{
@Test(dataProvider = "dp1" ,threadPoolSize=3,invocationCount=1)

public void testMethod(int number)
{
    Long id = Thread.currentThread().getId();
    System.out.println("HELLO :  " + id);
}


@DataProvider(name = "dp1",parallel=true)
public Object[][] dp1() {
  return new Object[][] {
      new Object[] { 1 },
      new Object[] { 2 },
      new Object[] { 3 },
      new Object[] { 4 },
      new Object[] { 5 },
      new Object[] { 6 },
      new Object[] { 7 },
      new Object[] { 8 }

  };
}

}

The output i received is :

HELLO : 10

HELLO : 12

HELLO : 17

HELLO : 11

HELLO : 16

HELLO : 14

HELLO : 13

HELLO : 15

Spawned 10 threads while i specified 5 in the thread pool size . Could you please tell what has to be added to the above snippet to control the data provider thread pool size .

like image 446
sujith Avatar asked Jul 20 '15 16:07

sujith


People also ask

How do you run TestNG DataProvider in parallel?

Note here that test method is run on data in same sequence in which DataProvider pass it. The reason behind this is that a DataProvider annotated method has an attribute named “parallel” whose default value is set to “false”. We can run it parallel as well by setting attribute “parallel” value as true.

How you achieve parallel execution using TestNG?

To trigger parallel test execution in TestNG, i.e., run tests on separate threads, we need to set the parallel attribute. This attribute accepts four values: methods – runs all methods with @Test annotation in parallel mode. tests – runs all test cases present inside <test> tag in the XML in parallel mode.

Does TestNG allow parallel execution?

Allow Multi-Threaded Tests: Using the parallel execution in TestNG, we can allow multiple threads to run simultaneously on the test case providing independence in the execution of different components of the software.


1 Answers

You need to use dataproviderthreadcount. The threadpoolsize and invocationcount values are not required. See details here.

like image 187
niharika_neo Avatar answered Sep 30 '22 19:09

niharika_neo