首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使测试用例失败- Cucumber with Groovy

如何使测试用例失败- Cucumber with Groovy
EN

Stack Overflow用户
提问于 2019-06-24 15:15:44
回答 1查看 68关注 0票数 0

当我检查步骤定义文件中的特定cucumber步骤时,如果条件为false,我希望使该特定测试用例停止并失败,然后继续下一个测试用例。

如果我必须使用FailureHandling.STOP_ON_FAILURE,如何编写这行代码?

代码语言:javascript
复制
@When("User enters the (.*) in the Login")
def user_enter_userid_in_the_Login(String uid) {
if (uid=='')
    /** FAIL the TEST CASE **/
else
    WebUI.setText(findTestObject('Object Repository/ORTC01/Page_/input_userid'), uid,
     FailureHandling.STOP_ON_FAILURE)
    WebUI.delay(5)
}
EN

回答 1

Stack Overflow用户

发布于 2019-06-24 19:45:57

代码语言:javascript
复制
def user_enter_userid_in_the_Login(String uid) {
    assert uid!='' //this will fail test if uid==''
    ...continue success code
}

也可以提供错误消息

代码语言:javascript
复制
assert uid!='' : "the parameter 'uid' could not be empty"

它大致对应于:

代码语言:javascript
复制
if(uid=='')throw new Exception("the parameter 'uid' could not be empty")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56731520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档