【问题标题】:How to pass in negative numbers for specflow example in a scenario outline?如何在场景大纲中为 specflow 示例传递负数?
【发布时间】:2015-07-16 13:38:15
【问题描述】:

我有这个功能

Feature: Selling Holiday
    As a person selling holiday
    I want to know the bonus per month

Scenario Outline: Selling Holiday
    Given I am selling holiday
    And I have a current salary rate of <rate> pounds an hour
    And I have chosen <hours> hours
    Then the cost should be <cost>

Examples: 
    | rate  | hours | cost  |
    | 9.00  | 14    | -10.2 |
    | 12.00 | 14    | -14   |
    | 8.0   | 7.5   | -5    |

[Then]
public void Then_the_cost_should_be_COST(decimal cost)
{
    //Cost is always positive :(
    Assert.AreEqual(cost, holidayCostCalculator.CalculateCost();
}

问题在于成本正像我所说的那样积极而不是消极地传递到步骤中。

这里还有一个问题,他们通过添加属性解决了这个问题,但在我看来这不是一个可接受的解决方案,因为它一点也不直观。

【问题讨论】:

  • 如果它没有通过,那么听起来可能是一个错误。您使用的是什么版本(nuget 和扩展)?可能值得在 github 上提出一个问题,我也许可以在接下来的几天内查看它。作为一种解决方法,您可以让此步骤临时在属性中使用正则表达式。
  • 我的扩展名是2015.1.2,nuget 版本是1.9。我刚刚发现了一个开放的问题,但它可能已经过时了,因为它自 2012 年以来就一直开放。github.com/techtalk/SpecFlow/issues/246。如果有帮助,我很乐意开一个新的。
  • 似乎是同一个问题。看到您已经更新了扩展,您可以尝试从 ci.appveyor.com/nuget/specflow-ci 构建的 v2 nuget beta 版本,以防万一它神奇地自行修复。
  • 刚刚用 v2 源试了一下,恐怕还是同样的问题。
  • 好的,太好了。谢谢。我试试看。

标签: nunit specflow


【解决方案1】:

使用传统的步法

[Then(@"the cost should be (.*)")]
public void ThenTheCostShouldBe(Decimal cost)
{
}

为了避免输入字符串问题,从表中的值中删除尾随零:

| rate | hours | cost  |
| 9    | 14    | -10.2 |
| 12   | 14    | -14   |
| 8    | 7     | -5    |

【讨论】:

    【解决方案2】:

    PR submitted 来解决这个问题。我相信它应该会在几周后发布 2.1 版本。

    【讨论】:

      猜你喜欢
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 2017-03-28
      • 2021-04-29
      • 2016-01-25
      • 2021-09-14
      • 1970-01-01
      相关资源
      最近更新 更多