将SpecFlow测试结构化为功能

时间:2018-03-22 08:14:52

标签: bdd specflow scenarios

鉴于Before / After-Scenario是实例方法属性但是Before / After-Feature是静态方法属性,是否有办法在特征文件中构建场景以便它们可以相互受益?

我认为如果无法保证方案的执行顺序,那么这将是一个纯粹的学术问题吗?

附录:当一个要素文件有多个场景时,每个场景执行一次或每个功能执行一次背景场景?这会使上述问题的答案复杂化,我认为(?)

1 个答案:

答案 0 :(得分:1)

背景

每个方案运行一次背景(该特征中的每个方案),即:

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

依赖其他场景的场景

情景不应完全依赖于彼此。运行测试的顺序应该能够在不影响测试功能的情况下进行更改。

这意味着在每个方案的基础上设置测试。其中一个例子是Backgrounds(如上所示),或者在“Given”步骤中到达同一点。

如果我使用上面的示例执行此操作:

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

<击>