0

I am trying to execute testng tests in parallel with Data Provider. Each input of Data Provider will be a new test.
For parallel execution, i have added attribute parallel to data provider & threadPoolSize to Test. I am passing command line arguments in eclipse Run Configuration -parallel methods -dataproviderthreadcount 2
Below is code snippet tried so far

  public class DemoTest { 

  @Test(dataProvider = "dp",invocationCount=1,threadPoolSize=2)
  public void f(Integer n, String s) {
  System.out.println("id:"+Thread.currentThread().getId()+" n:"+n+" s:"+s);
  }

@BeforeMethod
public void beforeMethod() {
 }

 @AfterMethod
 public void afterMethod() {
 }


 @DataProvider(parallel=true)
 public Object[][] dp() {
return new Object[][] {
  new Object[] { 1, "a" },
  new Object[] { 2, "b" },
  new Object[] { 3, "c" },
  new Object[] { 4, "d" },
  new Object[] { 5, "e" },
  new Object[] { 6, "f" },
  new Object[] { 7, "g" },
  new Object[] { 8, "h" },
  new Object[] { 9, "i" },
  new Object[] { 10,"j" }
  };
 }
}    

Output:
id:10 n:1 s:a
id:14 n:5 s:e
id:17 n:8 s:h
id:13 n:4 s:d
id:11 n:2 s:b
id:15 n:6 s:f
id:12 n:3 s:c
id:19 n:10 s:j
id:18 n:9 s:i
id:16 n:7 s:g

A new thread is created for each input, but I want only 2 threads to be created.

Grishma Oswal
  • 303
  • 1
  • 7
  • 22

0 Answers0