小黄瓜,两个场景可以相互依赖吗
Scenario1
When a new user clicks on sign up page
And provides login ID
Then user is signed up and can view profile page.
Scenario2
When user clicks on the edit profile page
And updates his address
Then updated profile should be visible to user
这些场景以相同的顺序写入功能文件中.当为它编写黄瓜文件时,我正在场景1中创建一个用户.在场景2中,正在更新同一用户.在某种程度上,方案2依赖于1,因为它正在更新在方案1中创建的同一用户.
The scenarios are written in a feature file in the same sequence. When writing the cucumber file for the same, I am creating a user in the scenario 1. And in scenario 2 , the same user is being updated. In a way, scenario2 is dependent on 1 as it is updating the same user that was created in scenario1.
我的问题是是否应该创建方案,以便它们依赖于其他方案.否则它们应该彼此独立执行.在这种情况下,我应该在场景2中创建一个新用户,然后对其执行并更新并声明它.
My question is should the scenarios be created so that they are dependent on other scenarios. Or they should be independent of each other execution.. in which case I should create a new user in scenario2 and then perform and update on it and assert it.
黄瓜明确建议您不要使方案相互依赖.从常见问题解答:
Cucumber explicitly recommends you do not make your Scenarios depend on each other. From the FAQ's:
每种情况都应该是独立的;您应该能够以任何顺序或并行运行它们,而不会干扰一种情况.
"Each scenario should be independent; you should be able to run them in any order or in parallel without one scenario interfering with another.
每个方案都应该精确地测试一件事,以便在失败时出于明确的原因而失败.这意味着您不会在另一个方案中重复使用一个方案.
Each scenario should test exactly one thing so that when it fails, it fails for a clear reason. This means you wouldn’t reuse one scenario inside another scenario.
如果您的方案使用相同或相似的步骤,或在系统上执行类似的操作,则可以提取帮助程序方法来执行这些操作."
If your scenarios use the same or similar steps, or perform similar actions on your system, you can extract helper methods to do those things."
(旁注:根据个人经验,我可以告诉您,相互依赖/系统状态的测试将很快变得很难维护.强烈建议您独立进行测试!)
(Sidenote: From personal experience, I can tell you that tests that depend on each other / the state of the system, will very quickly become very hard to maintain. I'd highly recommend you to make your tests independent!)