Reputation: 58063
Java - cucumber example
Looks like i am missing steps, it is complaining about missing steps and considering them as undefined
.feature file:
Feature: Roman Feature
Scenario: Convert Integer to Roman Number
Given I am on the demo page
When I pass number 1
Then the roman result is I
Scenario: Convert Integer to Roman Number
Given I am on the demo page
When I pass number 5
Then the roman result is V
Steps file:
@When("^I pass number (\\d+)$")
public void convert_numbers_to_roman(int arg1) throws Throwable {
// convert number
}
@Then("^the roman result is (\\d+)$")
public void the_roman_result_is(int result) throws Throwable {
// match result
}
When i run the test
Scenario: Convert Integer to Roman Number [90m# net/xeric/demos/roman.feature:3[0m
[32mGiven [0m[32mI am on the demo page[0m [90m# DemoSteps.i_am_on_the_demo_page()[0m
[32mWhen [0m[32mI pass number [0m[32m[1m1[0m [90m# DemoSteps.convert_numbers_to_roman(int)[0m
[33mThen [0m[33mthe roman result is I[0m
6 Scenarios 2 undefined You can implement missing steps with the snippets below:
@Then("^the roman result is I$")
public void the_roman_result_is_I() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Upvotes: 0
Views: 770
Reputation: 4323
I would consider catching the roman number as a string and therefore use the regular expression (.*)
You then
step would look like this:
@Then("^the roman result is (.*)$")
public void the_roman_result_is_I(String expectedRoman) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
This is similar to Sebastians answer, but in my view, a simpler regular expression. It catches any string and passes it as a parameter.
The assertion you probably will implement in the step will tell you if there is something broken. It might be easier to trouble shoot an failed assertion than to trouble shoot a missing step.
Upvotes: 1
Reputation: 4854
The problem is in your regex - \d
will only match an Arabic numeral (that's \\d
in Java-ese).
What you really want is ^the roman result is ([IVMCLX]+)$
. This will match one or more of the Roman numeral characters, sticking the results into your string of choice.
Upvotes: 0