esh*_*han 1 bdd requirements cucumber
我读过示例规范和几篇 BDD 文章,它们都说要避免功能描述和场景中的特定表单字段之类的细节。但是,如果示例中没有说明我们需要哪些表单字段以及哪些验证是合适的,那么它在哪里呢?
我正在考虑将所有表单字段放入场景中,并为每个验证设置一个场景。看起来开销很大;有没有更好的办法?
编辑:例如,采用以下内容。
Feature: Add new product
In order to sell a new product on our website
As an internal user
I want to add the product to our catalog
Scenario: Successful addition
Given I am logged in
When I try to add a new product
And I provide "Widget" as the name
And I provide 1 lb. as the weight
And I provide 1 inch as the height
And I provide 2 inches as the width
And I provide 3 inches as the length
Then I see the new product that was added
Scenario: Duplicate name
Given I am logged in
And an existing product named "Dupe"
When I try to add a new product
And I provide "Dupe" as the name
Then I see a duplicate name error
Scenario: Invalid Weight
Given I am logged in
When I try to add a new product
And I provide -1 as the weight
Then I see an invalid weight error
Scenario: Invalid Height
Given I am logged in
When I try to add a new product
And I provide -1 as the height
Then I see an invalid height error
Scenario: Invalid Width
Given I am logged in
When I try to add a new product
And I provide -1 as the width
Then I see an invalid width error
Scenario: Invalid Length
Given I am logged in
When I try to add a new product
And I provide -1 as the length
Then I see an invalid length error
Run Code Online (Sandbox Code Playgroud)
关键是从场景中删除与特定测试无关的所有内容。它们只是分散注意力的噪音。详细信息应在步骤定义中。
例如,我们以这个为例:
Scenario: Successful addition
Given I am logged in
When I try to add a new product
And I provide "Widget" as the name
And I provide 1 lb. as the weight
And I provide 1 inch as the height
And I provide 2 inches as the width
And I provide 3 inches as the length
Then I see the new product that was added
Run Code Online (Sandbox Code Playgroud)
这里有很多重复,而且它在风格上根本不是“对话式”的——你不会用这样的语言来解释它是如何工作的。给出了具体尺寸,但没有任何原因 - 您将进行其他测试来检查尺寸边界。这里没有测试尺寸。您可以轻松地将其更改为:
Given I am logged in
When I try to add a new product named "Widget"
And specify the weight and dimensions
Then I see the new product that was added
Run Code Online (Sandbox Code Playgroud)
这更接近您向其他人描述测试的方式,并隐藏步骤定义中的详细信息。
归档时间: |
|
查看次数: |
2061 次 |
最近记录: |