For a Behavior test that I'm trying to write, I require inputs that are floating point. How do I set up my gherkin string to look for these values?
Cucumber JVM: How do I use a double as an input value?
Asked Answered
Simple (.+)
should work
Given I have a floating point 1.2345 number
@Given("^I have a floating point (.+) number$")
public void I_have_a_floating_point_number(double arg) throws Throwable {
...
}
My own preference is to specify digits either side of a dot, something like...
@Given("^the floating point value of (\\d+.\\d+)$")
public void theFloatingPointValueOf(double arg) {
// assert something
}
and as you mentioned floating point inputs plural, I might handle the multiple inputs with an outline like...
Scenario Outline: handling lots of floating point inputs
Given the floating point value of <floatingPoint>
When something happens
Then some outcome
Examples:
| floatingPoint |
| 2.0 |
| 2.4 |
| 5.8 |
| 3.2 |
And it will run a scenario per floating point input
I use the form
@When("^We change the zone of the alert to \\(([0-9\\.]+),([0-9\\.]+)\\) with a radius of (\\d+) meters.$")
public void we_change_the_zone_of_the_alert_to_with_a_radius_of_meters(double latitude, double longitude, int radius)
so [0-9.]+
make the deal :)
Take care of the local of your cucumber. If you're using language:fr
for example, number are using ,
for delimiter.
The language makes the difference! It's the same for language: de. Thanks! –
Arica
You should escape the float number with (\\d+)
Example
Given I have a floating point 1.2345 number
@Given("^I have a floating point (\\d+) number$")
public void I_have_a_floating_point(double arg){
}
That was not the matter of the question –
Gravy
© 2022 - 2024 — McMap. All rights reserved.