6

对于我正在尝试编写的行为测试,我需要浮点输入。如何设置我的小黄瓜字符串来查找这些值?

4

4 回答 4

10

简单(.+)应该工作

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 { 
    ... 
}
于 2013-02-27T01:38:07.983 回答
5

我自己的偏好是在点的任一侧指定数字,例如...

@Given("^the floating point value of (\\d+.\\d+)$")
public void theFloatingPointValueOf(double arg) {
    // assert something
}

正如你提到的浮点输入复数,我可能会处理多个输入的轮廓,如......

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           |

它会为每个浮点输入运行一个场景

于 2015-11-02T11:46:52.370 回答
2

我使用表格

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

所以[0-9.]+做交易:)

照顾当地的黄瓜。language:fr例如,如果您使用的是数字,作为分隔符。

于 2014-09-15T14:40:00.840 回答
-1

你应该转义浮点数(\\d+)

例子

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

}
于 2013-12-03T13:12:47.603 回答