gauge framework exception

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);
    }
}

Upvotes: 2

Views: 656

Answers (1)

Srikanth Venugopalan
Srikanth Venugopalan

Reputation: 9049

Gauge allows you to mark a step implementation with ContinueOnFailure which notifies the framework that your test code may throw an exception and it should ignore it.

You can specify the type of exception to be ignored explicitly, ex. in your case FieldFunctionException.class.

See this for further reference.

Upvotes: 1

Related Questions