一个功能文件中的多个场景 - 如何清除第一个场景中添加的项目?
multiple scenarios in one feature files - how to clear the item added at first scenario?
我正在编写待办事项应用程序的测试脚本。
预期的应该是第一个场景有
“第一个待办事项 #1”
然后添加了第二个场景
“下一个待办事项”
总共只有 2 项。
但实际结果我得到了 3 个项目。
是不是我写剧本的方式不对?
Scenario: Add first item
Given my todo list is empty
When I add "First todo item #1"
Then my todo list should contain:
| First todo item #1|
And the remaining item count should show "1 item left"
Scenario: Add another item
Given I have a todo list containing
| First todo item #1 |
When I add "Next todo item"
Then my todo list should contain:
| Next todo item |
| First todo item #1 |
And the remaining item count should show "2 items left"
每个场景都应该是独立的。你为什么不加入你的场景?您可以添加在每个场景之前执行的 background 部分:
Background:
Given my todo list is empty
Scenario: Item addition
When I add "First todo item #1"
Then my todo list should contain:
| First todo item #1|
And the remaining item count should show "1 item left"
When I add "Next todo item"
Then my todo list should contain:
| Next todo item |
| First todo item #1 |
And the remaining item count should show "2 items left"
Scenario: Item edition
...
我正在编写待办事项应用程序的测试脚本。
预期的应该是第一个场景有 “第一个待办事项 #1”
然后添加了第二个场景 “下一个待办事项”
总共只有 2 项。
但实际结果我得到了 3 个项目。
是不是我写剧本的方式不对?
Scenario: Add first item
Given my todo list is empty
When I add "First todo item #1"
Then my todo list should contain:
| First todo item #1|
And the remaining item count should show "1 item left"
Scenario: Add another item
Given I have a todo list containing
| First todo item #1 |
When I add "Next todo item"
Then my todo list should contain:
| Next todo item |
| First todo item #1 |
And the remaining item count should show "2 items left"
每个场景都应该是独立的。你为什么不加入你的场景?您可以添加在每个场景之前执行的 background 部分:
Background:
Given my todo list is empty
Scenario: Item addition
When I add "First todo item #1"
Then my todo list should contain:
| First todo item #1|
And the remaining item count should show "1 item left"
When I add "Next todo item"
Then my todo list should contain:
| Next todo item |
| First todo item #1 |
And the remaining item count should show "2 items left"
Scenario: Item edition
...