gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 03:13:00 25 4
gpt4 key购买 nike

我有这个功能

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

问题是,正如我所说的那样,成本以正而不是负的方式传递到步骤中。

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

最佳答案

使用传统的台阶样式

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

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

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

关于nunit - 如何在场景大纲中为 specflow 示例传递负数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31455830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com