I\'m using TestNG
for Eclipse
.
Is it possible to give two data providers step by step to the same test-function?
I co
@DataProvider
public Object[][] combinedDataProvider() {
return Stream.of(dp1(), dp2())
.flatMap(Arrays::stream)
.toArray(Object[][]::new);
}
Please refer to this answer:
TestNG using multiple DataProviders with single Test method
It is much cleaner and will work for more complex things.
Maybe someone will need it too, I rewrote this method public static T[] concatAll(T[] first, T[]... rest)
in a different way:
public static Object[] concat(Object[] first, Object[] second) {
Object[] result = ArrayUtils.addAll(first, second);
return result;
}
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);
}
Yes,
You can write @Test(dataProvider="name_of_first_dataprovider,name_of_second_dataprovider")