7

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?

user321605
  • 846
  • 2
  • 7
  • 20

4 Answers4

11

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 { 
    ... 
}
denis.solonenko
  • 11,645
  • 2
  • 28
  • 23
5

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

Jeremy
  • 3,418
  • 2
  • 32
  • 42
2

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.

twillouer
  • 1,149
  • 9
  • 14
-1

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){

}
Petsome
  • 49
  • 8