TestNG: More than one @DataProvider for one @Test
No, but nothing stops you from merging these two data providers into one and specifying that one as your data provider:
public Object[][] dp1() {
return new Object[][] {
new Object[] { "a", "b" },
new Object[] { "c", "d" },
};
}
public Object[][] dp2() {
return new Object[][] {
new Object[] { "e", "f" },
new Object[] { "g", "h" },
};
}
@DataProvider
public Object[][] dp() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(dp1()));
result.addAll(Arrays.asList(dp2()));
return result.toArray(new Object[result.size()][]);
}
@Test(dataProvider = "dp")
public void f(String a, String b) {
System.out.println("f " + a + " " + b);
}
@DataProvider
public Object[][] combinedDataProvider() {
// Using stream to combine the two separate data providers.
return Stream.of(dp1(), dp2())
.flatMap(Arrays::stream)
.toArray(Object[][]::new);
}