如何在场景大纲中传递specflow示例的负数?

时间:2015-07-16 13:38:15

标签: nunit specflow

我有这个功能

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();
}

问题在于,成本正在以正面而非负面的方式传递到步骤中。

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

2 个答案:

答案 0 :(得分:3)

使用传统的步骤式

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

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

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

答案 1 :(得分:0)

PR submitted来解决此问题。它应该发布2.1版本,我相信它会安排几周。