【问题标题】:Cucumber JVM: How do I use a double as an input value?Cucumber JVM:如何使用双精度值作为输入值?
【发布时间】:2013-02-15 19:37:14
【问题描述】:

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

【问题讨论】:

    标签: regex cucumber cucumber-jvm cucumber-junit


    【解决方案1】:

    简单的(.+) 应该可以工作

    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 { 
        ... 
    }
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        【解决方案3】:

        我使用表格

         @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,则数字使用, 作为分隔符。

        【讨论】:

        • 语言与众不同!语言也是一样的:de。谢谢!
        【解决方案4】:

        你应该用(\\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){
        
        }
        

        【讨论】:

        • 这不是问题的问题
        猜你喜欢
        • 2021-07-01
        • 1970-01-01
        • 2012-06-03
        • 1970-01-01
        • 1970-01-01
        • 2019-05-18
        • 1970-01-01
        • 1970-01-01
        • 2014-10-26
        相关资源
        最近更新 更多