Is it possible to set the expectedExceptions
option in a TestNG @Test
from a @DataProvider
? If so, how is it done?
Here is a non-intuitive example:
@DataProvider
private Object[][] methodABadArgsProvider() {
return new Object[][] {
{null, "arg2", "arg3"}, // expect NullPointerException
{"arg1", null, "arg3"}, // expect IllegalArgumentException
{"arg1", "arg2", null} // expect OperationNotSupportedException
}
}
@Test(expectedException = [tbd].class, dataProvider = "methodABadArgsProvider")
public void methodABadArgs(String arg1, String arg2, String arg3) {
testInstance.methodA(arg1, arg2, arg3);
}