【问题标题】:Structuring SpecFlow tests as features将 SpecFlow 测试构建为特征
【发布时间】:2018-08-31 14:12:02
【问题描述】:

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

我假设如果没有办法保证场景的执行顺序,那么这将是一个纯粹的学术问题?

附录:当一个特征文件有多个场景时,后台场景是每个场景执行一次还是每个特征执行一次?我认为这会使上述问题的答案复杂化(?)

【问题讨论】:

  • 每个场景(该功能中的每个场景)后台运行一次。场景不应相互依赖
  • 将其发布为答案,我会接受。谢谢。

标签: bdd specflow scenarios


【解决方案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

依赖其他场景的场景

场景不应该相互依赖。运行测试的顺序应该能够在不影响测试功能的情况下更改。

这意味着根据每个场景设置您的测试。这方面的一个例子是背景(如上所示),或者在“给定”步骤中到达同一点。

如果我用上面的例子来做这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-03
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2020-05-09
    相关资源
    最近更新 更多