Consider an example:
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class DataProviderExampleTest {
@Test(dataProvider="data")
public void testDataProvider(int p1, String p2) {
/*
assert block for all p1 and p2 parameters
*/
// ???
// how to put p1 and p2 specific assertions here?
//jst for example
if (p2.equals("myString")) {
//asserts for myString
}
if (p2.equals("otherString")) {
//asserts for otherString
}
}
@DataProvider
public Object[][] data() {
return new Object[][]{/*dozen objects here*/};
}
}
The example is simplified, in real life p1
and p2
can be very complex objects with subclasses which require complex assertions.
Does testng provides some api to put parameter's specific assertion somewhere, but without creating too long if
or switch
conditions?
(For my opinion if
and switch
is like duplicate business logic in test and should be avoided)
Also what data driven development approach suggest to do in such situations when all
elements can be checked with general algorithm, but only a few with specific?