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);
}
DataProvider has access to test context. It's not possible to it via dp; but you can use AnnotationTransformer if it allows to do what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With