[英]JBehave ambiguous step
Say I have: 说我有:
@Given("first name is $firstName")
@Given("first name is $firstName and last name is $lastName")
The following step would be marked as ambiguous: 以下步骤将标记为含糊不清:
Given first name is John and last name is Smith
Without using quotes to surround the first parameter, how can I fix this step so it only matches the second one? 如果不使用引号括起第一个参数,我该如何修复此步骤以使其仅匹配第二个参数? Using quotes to surround both the parameters separately also has the same ambiguity issue. 使用引号分别围绕这两个参数也具有相同的模糊性问题。
Is there a limit on how long each parameter is? 每个参数的长度是否有限制? Are there certain characters that can't be passed in? 是否有某些字符无法传入?
You can solve this by using step priorities, as documented here: http://jbehave.org/reference/stable/prioritising-steps.html 您可以使用步骤优先级来解决此问题,如下所示: http : //jbehave.org/reference/stable/prioritising-steps.html
Your problem would be solved by setting a higher priority to the variant with two parameters: 通过使用两个参数为变量设置更高的优先级,可以解决您的问题:
@Given("first name is $firstName")
@Given(value = "first name is $firstName and last name is $lastName", priority = 1)
I tried your example and with this combination, the two steps were separated. 我试过你的例子,用这个组合,两个步骤分开了。
(Edit: my initial solution had quotes for the parameters, but it works without as well) (编辑:我的初始解决方案有参数的引用,但它的工作没有那么好)
I think this scenario can be write this way: 我认为这种情况可以这样写:
Given first name is John
And last name is Smith
And the steps: 步骤:
@Given("first name is $firstName")
@And("last name is $lastName")
You can create the person object first an set the name and the last name in the "@Given" steps. 您可以先创建person对象,然后在“@Given”步骤中设置名称和姓氏。
If you need add another property, like email, you just need create another step: 如果您需要添加其他属性,例如电子邮件,则只需创建另一个步骤:
@And("the email is $email")
public addEmail(String email) {
person.setEmail(email);
}
So this problem not gonna happen and you code will be more reusable. 所以这个问题不会发生,你的代码将更加可重用。
What worked for me was substituting ankle brackets (<>) for the dollar sign ($), ie 对我有用的是用脚踝括号(<>)代替美元符号($),即
@Given("a person with first name <firstName>")
and 和
@Given("a person with first name <firstName> and last name <lastName>")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.