BDD - should each scenario be self contained?

2020-07-24 06:06发布

问题:

I have a BDD feature containing multiple scenarios. Should each scenario be completely self contained and runnable individually?

回答1:

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.



标签: bdd