TestNG parallel Execution with DataProvider

sujith picture sujith · Jul 20, 2015 · Viewed 26.7k times · Source

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 .

Answer

niharika_neo picture niharika_neo · Jul 21, 2015

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