【发布时间】:2013-02-15 19:37:14
【问题描述】:
对于我正在尝试编写的行为测试,我需要浮点输入。如何设置我的小黄瓜字符串来查找这些值?
【问题讨论】:
标签: regex cucumber cucumber-jvm cucumber-junit
对于我正在尝试编写的行为测试,我需要浮点输入。如何设置我的小黄瓜字符串来查找这些值?
【问题讨论】:
标签: regex cucumber cucumber-jvm cucumber-junit
简单的(.+) 应该可以工作
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 {
...
}
【讨论】:
我自己的偏好是在点的任一侧指定数字,例如...
@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 |
它会为每个浮点输入运行一个场景
【讨论】:
我使用表格
@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,则数字使用, 作为分隔符。
【讨论】:
你应该用(\\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){
}
【讨论】: