BDD - should each scenario be self contained?

旧巷老猫 提交于 2019-12-04 16:49:07

Should be, yes. It is generally good practise in all forms of TDD (BDD included) to make sure that each "test" can run independently, and isn't coupled with or have a dependency on another test having been run first. This will help avoid creating a brittle test suite (i.e. one that is prone to breaking).

That's not to say that you cannot chain readability together. For a very cheap/quick example:

Feature: Users can register and log in


Scenario: Should be able to register
Given I am not registered
When I complete the registration form
Then I will be registered

Scenario: Should be able to log in
Given I am registered
When I correctly sign-in with my credentials
Then I will be logged in

Scenario: Should be able to log out
Given I am logged in
When I sign-out
Then I will be logged out

Each scenario indicates a test that can be automated - and each should be designed behind the scenes to be able to run independently. But as a reader of the feature (say a business stakeholder) - the process is complete and they can understand the entire picture more easily.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!