背景
每个场景(该功能中的每个场景)运行一次后台,即:
Feature: Hello World
Background:
Given I go to the homepage
When I search for "Hello, World!"
Scenario: See a result
Then I should see a result
Scenario: See multiple results
Then I should see a maximum of 10 results
和写法一样:
Feature: Hello World
Scenario: See a result
Given I go to the homepage
When I search for "Hello, World!"
Then I should see a result
Scenario: See multiple results
Given I go to the homepage
When I search for "Hello, World!"
Then I should see a maximum of 10 results
依赖其他场景的场景
场景不应该相互依赖。运行测试的顺序应该能够在不影响测试功能的情况下更改。
这意味着根据每个场景设置您的测试。这方面的一个例子是背景(如上所示),或者在“给定”步骤中到达同一点。
如果我用上面的例子来做这个:
Feature: Hello World
Scenario: See a result
Given I have searched for "Hello, World!"
Then I should see a result
Scenario: See multiple results
Given I have searched for "Hello, World!"
Then I should see a maximum of 10 results
而不是做这样的事情(将其删除,以便明确不要这样做):
罢工>
Feature: Hello World
Scenario: See a result
Given I have searched for "Hello, World!"
Then I should see a result
Scenario: See multiple results
Then I should see a maximum of 10 results