行为驱动开发(,BDD)场景有效地表达了系统应该如何运行的示例,但在编写了数百个示例之后,我发现它们没有全面地表达业务规则。
例如,在丹·诺斯对BDD的介绍中,它展示了如何表达银行处理客户现金请求的方案。尽管它显示了如果客户的帐户超过或低于透支限额应该发生的情况,但是这些场景实际上并没有定义业务规则。
场景1:帐户在中
Given the account is in credit
And the card is valid
And the dispenser contains cash
When the customer requests cash
Then ensure the account is debited
And ensure cash is dispensed
And ensure the card is returned场景2:帐户透支超过透支限额
Given the account is overdrawn
And the card is valid
When the customer requests cash
Then ensure a rejection message is displayed
And ensure cash is not dispensed
And ensure the card is returned透支限额是多少?以这种方式编写BDD场景并不能有效地表达业务规则。如何使用BDD场景来表示业务逻辑?
我一直试图使用Gherkin定义的BDD的“场景大纲”来表达BDD场景中的业务逻辑。在场景标题中,我将重点放在用户操作上,然后指定响应应该依赖的内容。我简明扼要地说明了业务规则,例如透支限额是1000美元。以下是它的外观:
场景:申请现金不应超过1000美元透支限额
Given the account is in <account_state>
And the card is valid
And the dispenser contains cash
When the customer requests cash
Then ensure <customer_response>
And ensure cash is <cash_response>
And ensure the card is returned
Examples:
| account_state | customer_response | cash_response |
| in credit | the account is debited | dispensed |
| overdrawn | a rejection message is displayed | not dispensed |在BDD中的规范模式与规范模式中,它谈到了如何表达业务逻辑,但对此表示了一些困惑。也许它是说业务逻辑应该用领域驱动设计(,DDD)来表示,而示例应该表示为BDD方案的接受标准。但是我不知道DDD,我更愿意看看BDD场景是如何用不同的方式来表达业务逻辑的。
是否有更好的方法将整个业务描述为BDD场景?我们不需要简单的例子,我们想要的是规则。通过类比,在数学中,你可以表示曲线上的点,也可以表示适合所有这些点的方程。我们要的是等式,而不是点。
发布于 2021-02-27 10:49:36
您可以在特性文件的顶部用免费文本编写规则,然后在场景中举例说明这些规则。
发布于 2021-03-01 14:27:09
步骤Given the account is overdrawn在步骤定义中有硬编码的透支限制,很可能是这样。在这种特殊情况下,透支限制不是要测试的行为。正在测试的行为是试图从透支帐户中提取现金。透支限额并不是场景的重要细节,因此没有指定透支量。
透支限额的具体金额将是它自己的场景--最有可能是多个场景。
https://stackoverflow.com/questions/66378428
复制相似问题