我是黄瓜的新手,目前仍在努力组织/构建一些功能/场景。我试图捕获的行为是使用我的网站的用户,访客和管理员的行为。该网站主要用于创建私人和公共待办事项列表。
这些是我想测试的特定场景:
现在我要用这样的东西:
Feature: Managing Todo lists
In order to be more productive
As a user of the site
I want to be able to manage todo lists
Background:
Given a user named "user-one@email.com" with password "secret-one"
Given a user named "user-two@email.com" with password "secret-two"
Given an admin named "admin@email.com" with password "admin"
Scenario: user-one@email.com can view his own private todo lists
Scenario: user-one@email.com can not view user-two@email.com private todo lists
Scenario: admin@email.com can view user-one@email.com and user-two@email.com private todo lists
Scenario: user-one@email.com can create private todo lists
Scenario: user-one@email.com can delete todo lists they own
Scenario: admin@email.com can delete user-one@email todo list
Scenario: guests can view all public todo lists
我遇到的问题是每种方案的设置。例如,在第一个场景中,我必须假设user-one@email.com
已登录。在第一个admin@email.com
场景中,我必须假设管理员已登录。在最后一个场景中,我需要假设没有人是登录。
那么如何管理这些Given
?我只是添加一个
Given user-one@email.com is logged in
对于每一种情况?或者有更好的方法来构建这一切吗?请帮忙!我确信这是黄瓜用户需要测试的一种非常常见的模式。
答案 0 :(得分:1)
通常我会尝试仅列出重要的步骤。在你的情况下,我会做类似的事情:
Feature: Managing Todo lists
In order to be more productive
As a user of the site
I want to be able to manage todo lists
Background:
Given a user named "user-one@email.com" with password "secret-one"
Given a user named "user-two@email.com" with password "secret-two"
Given an admin named "admin@email.com" with password "admin"
Scenario: Users can see own private todo lists
Given user "user-one" has a private todo list
Then user "user-one" can see the private todo list of "user-one"
Scenario: Users cannot see others private todo lists
Given user "user-one" has a private todo list
Then user "user-two" cannot see the private todo list of "user-one"
如果您在其他地方有登录步骤,则可以在Then user "user-one" can see the private todo list of "user-one"
步骤定义中重复使用该步骤,而不是在功能中。或者您的步骤可以直接共享相同的代码。
请参阅step re-use