Reputation: 637
I'd like to run test methods in a class parallely with data provider. I would need a data provider that gets called every time before a new test method starts to generate partly dynamic data for the given test run. Let me explain it in pseudo code:
@DataProvider(parallel=true)
public Object[][] dp(){
User user = createNewUser();
return new Object[][]{
{"s1", new AExtendsOtherObject(user), user},
{"s2", new BExtendsOtherObject("any"), user},
}
@Test(dataProvider = "dp")
void test(String s, OtherObject o, User user){
}
<suite name="all" verbose="1" parallel="methods" data-provider-thread-count="5">
How could I achieve this?
Upvotes: 1
Views: 86
Reputation: 637
Ok, so now that I realised what I really want my question looks a bit stupid. Sorry for that. Anyway, here is my solution:
@DataProvider(parallel=true)
public Iterator<Object[]> dp(){
List<Object[]> list = new ArrayList<>();
User user = createNewUser();
list.add(new Object[]{"s1", new AExtendsOtherObject(user), user});
user = createNewUser();
list.add(new Object[] {"s2", new BExtendsOtherObject("any"), user});
return list.iterator();
}
The only problem with this solution is that if the createNewUser() takes a lot of time then it will take it upfront at once before any test method could start.
Upvotes: 1
Reputation: 600
Have you try this? From the public doc:
https://howtodoinjava.com/testng/testng-executing-parallel-tests/#test_in_multiple_threads
Upvotes: 0