我正在为我们的企业开发自动付款处理服务。我们正在尝试实现规范流程,并且当条件
时我们已成功完成了1Scenario Outline: Stub matches NEXT oldest outstanding bill
Given I have a group with the following bills:
| Id | Due Date | Status | Amount Due |
| Bill A | 9/14/2011 | <Oldest Bill Status> | 1100.00 |
| Bill B | 10/14/2011 | Unpaid | 1200.00 |
| Bill C | 11/14/2011 | Unpaid | 1300.00 |
When a stub is received that matches 'Bill B'
And the Payment Amount is <Payment Amount>
Then the allocation result should <Allocation Result>
And Review should <Review>
Examples:
| Oldest Bill Status | Allocation Result | Review | Payment Amount |
| Reconciled | Allocate to Bill | not required | 1200.00 |
[When(@"a stub is received that matches '(.*)'")]
public void WhenAStubIsReceivedThatMatches(string billKeyName)
{
// Method
}
我不确定在执行结果步骤之前如何更改钩子来处理这两个条件。
答案 0 :(得分:2)
最佳做法是使用一个When语句。
一些选项包括:
When a stub is received that matches 'Bill B' for <Payment Amount>
因此:
[When(@"a stub is received that matches '(.*)' for ([\d\.]*)")]
public void WhenAStubIsReceivedThatMatches(string billKeyName, decimal amount)
{
// create stub and "recieve" it
}
OR
Given ...etc...
And I have a stub is received that matches 'Bill B' for <Payment Amount>
When I receive the stub
...因为存根本身不是被测试的对象,它是背景数据,可以合理地创建为你的数量的一部分。
答案 1 :(得分:1)
有多个When-clause被废弃......我认为你可以理解(并解释)为什么,因为你提出这个问题。将几个动作放在一起很难,因为它们彼此依赖。
尝试使用简单的When子句编写规范,而是编写不同的场景来描述不同的交互方式。
因此,对于您的场景,如果您愿意,尝试找出发生的重要状态转换,以便从Given-state转到Then-state。
这是我发现用于编写场景的一个小方法
几个星期前我和Gjoko Adzic一起参加了一个课程,并且收到了很多这样的提示。 Read about it here