Php 如何处理在';然后';阶段
他们认为BDD的基本规则是: 一个场景,一个行为 这很好,但事实是,我有一个单一的行动,将触发系统中的许多不同的事情。。我必须证实所有这些都会发生。这是我的小黄瓜:Php 如何处理在';然后';阶段,php,bdd,behat,Php,Bdd,Behat,他们认为BDD的基本规则是: 一个场景,一个行为 这很好,但事实是,我有一个单一的行动,将触发系统中的许多不同的事情。。我必须证实所有这些都会发生。这是我的小黄瓜: Scenario: Buying a single product to be delivered now Given I am in the checkout page When I checkout the order Then the order should be created to the sp
Scenario: Buying a single product to be delivered now
Given I am in the checkout page
When I checkout the order
Then the order should be created to the specified address
And the order should be set in pending state
And ops must be notified via a slack notification
And A shopper must be auto assigned the order via a push notification
And A retailer must be notified about the order via a push notification
And A transaction must be recorded in the payment gateway
And My wallet should be deducted by the payment amount
这看起来很难看。但现在我不知道怎么把它分开。做一个背景似乎并没有减少它,因为在一个背景中,您只是为多个场景打下基础,其中每个场景都会有它的“时间”和“然后”配对(在我的例子中,我在背景之后的每个场景中使用Behat,一个给定的“时间”和“然后”)
建议?解决这个问题最直接的方法是遵循您在问题中引用的建议: 一个场景,一个行为 要实现此建议,只需将臃肿的场景拆分为多个较小的场景 例如:
Scenario: Buying a single product to be delivered now
Given I am in the checkout page
When I checkout the order
Then the order should be created to the specified address
And the order should be set in pending state
Scenario: Notifying ops of the purchase
Given I am in the checkout page
When I checkout the order
Then ops must be notified via a slack notification
……等等
在您的场景中,许多给定的,彼此之间没有太大的关联。它们有一些时间关系,因为它们都发生在下订单之后,但仅此而已
<>你甚至可以进一步考虑将它们分组为不同的特征。
毕竟,通知ops与处理付款是不同的功能,而处理付款又不同于股票计算。除了@Stratadox(按行为划分场景)的答案之外,
给定的步骤决不能涉及用户界面或用户旅程中的某个阶段。用户所在的页面与业务逻辑无关
给定
步骤(如单元测试中的排列
步骤)用于将系统设置为给定状态。在给定的步骤中设置的此状态决定结果(然后步骤)
例如:
“应将订单创建到指定的地址”-此结果可能是由于客户正确输入其地址造成的(在这种情况下,可能需要指定实际地址,以便在然后步骤中断言)
“我的钱包应该按付款金额扣除”-为了在向您的钱包充电后断言系统处于正确状态,我们可能会检查某种数据持久性,还需要检查特定金额。多少钱?您在给定的步骤中指定的金额与此场景的结果直接相关
Scenario: Being charged the correct amount on successful purchase of product
Given I have £10 in my wallet
When I purchase a Toaster Oven for £4
Then I should have £6 left in my wallet
“购物者必须通过推送通知自动分配订单”-这是一个可以作为“成功购买”检查的一部分断言的结果。唯一要看的是这次收购是否成功。您可以将诸如“购物者通知,零售商通知交易记录”之类的断言捆绑在一起,并在您的场景中为它们指定一个名称和一行,例如:
Given Jon has the following items in his basket:
| Macbook Pro | £3000 |
When Jon checks out his basket
Then a purchase of "xyz" for £3000 by Jon should have gone through
这里的最后一步将意味着在幕后做三个断言。这很好,因为每个人都知道“购买过程”意味着什么