首页 > 解决方案 > 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);
    }
}

标签: javagetgauge

解决方案


Gauge 允许您标记一个步骤实现,使用ContinueOnFailure它通知框架您的测试代码可能会抛出异常并且它应该忽略它。

您可以指定要显式忽略的异常类型,例如。在你的情况下FieldFunctionException.class

请参阅以供进一步参考。


推荐阅读