Search code examples
javaambiguityjbehave

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?


Solution

  • You can solve this by using step priorities, as documented here: 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)