对于我正在尝试编写的行为测试,我需要浮点输入。如何设置我的小黄瓜字符串以查找这些值?
答案 0 :(得分:7)
简单(.+)
应该有效
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 {
...
}
答案 1 :(得分: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 |
它将为每个浮点输入运行一个场景
答案 2 :(得分: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
,则号码正在使用,
作为分隔符。
答案 3 :(得分:-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){
}