I'm starting to use the Gauge Framework to to some tests. I have some validation methods that return a custom Exception called FieldFunctionException when the value tested is not valid.
To test that in Junit, I used something like that:
@Test(expected = FieldFunctionException.class)
public void testAllowedValuesValidation_fail_1() throws FieldFunctionException {
...
}
Using Gauge framework:
@Step("Scenario failing ")
public void testAllowedValuesValidation_fail_1() throws FieldFunctionException {
...
}
But I didn't find how to inform Gauge that this test throwing an FieldFunctionException is the normal behavior.
Workaround:
In my case I want to test the exception. In other words, the exception throw is a success test scenario. The workaround I made to test the exception was something like that:
@Step("Scenario failing")
public void testAllowedValuesValidation_fail_1() throws FieldFunctionException {
AllowedValuesValidation f = new AllowedValuesValidation().allowedValues(new String[] { "Yes", "No", "Maybe" });
try {
String returned = f.execute("Maybes", null);
}catch (Exception e) {
assertTrue(e instanceof FieldFunctionException);
}
}