I have a test class with a number of methods, where each of them is fed up with parallel data provider. I want to achieve mixed order of methods execution but I cannot control the data provider thread pool size - it is mulitplicated by number of test methods. Please see example:
My test suite definition:
<suite data-provider-thread-count="5" parallel="methods" preserve-order="false" name="Data provider problem">
My test class:
@Test(dataProvider = "dp1")
public void test1(TestData testData) { }
@Test(dataProvider = "dp2")
public void test2(TestData testData) { }
@DataProvider(name = "dp1", parallel = true)
public static Object[][] dp1() {
return createTestData1();
}
@DataProvider(name = "dp2", parallel = true)
public static Object[][] dp2() {
return createTestData2();
}
With such test suite configuration I have achieved that executions of test1()
and test2()
are mixed, but data provider thread pool is not 5, but 10! Adding new test methods multiplicates number of threads. It is surprising to me as testNg documentation site says: "Parallel data providers running from an XML file share the same pool of threads". Am I just wrongly using suite 'parallel' attribute? If so, is it possible to achieve my goal (mixed order of methods execution together with data providers) by other means?
I've also tried to use one data provider and create test data on basis of injected test method, but it does not help either, see below:
@Test(dataProvider = "dp")
public void test1(TestData testData) { }
@Test(dataProvider = "dp")
public void test2(TestData testData) { }
@DataProvider(name = "dp", parallel = true)
public static Object[][] dp(Method m) {
if (m.getName().equals("test1")) {
return createTestData1();
}
if (m.getName().equals("test2")) {
return createTestData2();
}
return null;
}
Still I get 10 test executions running parallel. Moving data provider methods to separate class does not help either.
Did you try adjusting params for the @Test?
@Test(dataProvider = "dp", threadPoolSize=5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With