JBehave controversial move

Say I have:

@Given("first name is $firstName") @Given("first name is $firstName and last name is $lastName") 

The next step will be marked as ambiguous:

 Given first name is John and last name is Smith 

Without the use of quotation marks to surround the first parameter, how can I fix this step so that it matches only the second? Using quotes to isolate both parameters separately also has the same ambiguity problem.

Is there a limit on the duration of each parameter? Are there certain characters that cannot be transmitted?

+6
source share
3 answers

You can solve this using step priorities, as described here: http://jbehave.org/reference/stable/prioritising-steps.html

Your problem will be solved by setting a higher priority for the option 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 original solution had quotation marks for the parameters, but it works without it)

+8
source

I think this script can be written as follows:

 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 a person object first to specify the first and last name in the "@Given" steps.
If you need to add another property, such as email, you just need to create one more step:

 @And("the email is $email") public addEmail(String email) { person.setEmail(email); } 

So this problem will not happen, and the code will be more reusable.

+1
source

What worked for me was to replace the ankle brackets (<>) with a dollar sign ($), i.e.

 @Given("a person with first name <firstName>") 

and

 @Given("a person with first name <firstName> and last name <lastName>") 
0
source

All Articles