java - 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);
}
}
解决方案
Gauge 允许您标记一个步骤实现,使用ContinueOnFailure
它通知框架您的测试代码可能会抛出异常并且它应该忽略它。
您可以指定要显式忽略的异常类型,例如。在你的情况下FieldFunctionException.class
。
请参阅此以供进一步参考。
推荐阅读
- android - 如何在android中以编程方式将id添加到菜单项
- angular - 多次单击按钮时的Angular 6订阅清理
- javascript - 如何通过单击按钮两次提交表单
- powerbi - 反向过滤器和多对多关系
- arrays - VBA 中将完整数组从一个用户表单列表传输到另一个用户表单列表的最佳策略是什么?
- jira - 如何将一组 jira 项目迁移并合并到新服务器上的单个项目中?
- python - 在 Jinja2 If/elif 语句中加入字典元素
- java - Promise Returning play.libs.F$Promise@65722df2 instead of String Value
- java - 当用户没有在数组中输入任何数字或在数组中输入太多数字时打印出错误消息
- c - MPI_Recv() freezing program, not receiving value from MPI_Send() in C