Can you please let me know if we can merge the below 2 dataproviders
public Object[][] dp1() {
User user = new User(1L, "Arun");
Transaction trx = new Transaction(1L, "atm");
return new Object[][] {
new Object[] { user , trx, true }
};
}
public Object[][] dp2() {
return new Object[][] {
new Object[] { "e", "f" }
};
}
I want to merge them horizontally, after merge the following output is desired in the merged dataprovider { user , trx, true, "e", "f" }
there is no way to set multiple data provider in testNG, so i am using a utility method to merge as below.
@DataProvider(name = "myDataProvider")
public Object[][] myDataProvider() {
return mergeDataProviders(myDataProvider1(),myDataProvider2());
}
@DataProvider(name = "myDataProvider1")
public Object[][] myDataProvider1() {
return new Object[][]{};
}
@DataProvider(name = "myDataProvider2")
public Object[][] myDataProvider2() {
return new Object[][]{};
}
private static Object[][] mergeDataProviders(Object[][] ... dataProviders) {
return Arrays.stream(args)
.map(Arrays::asList)
.flatMap(List::stream).toArray(Object[][]::new);
}