【问题标题】:Specflow: Can some step definitions be used feature wide?Specflow:可以在功能范围内使用某些步骤定义吗?
【发布时间】:2013-03-15 20:36:22
【问题描述】:

当一个功能需要一些给定的步骤时,您需要为每个场景指定“鉴于我已经做了一些事情和其他事情以及最后一件事......”。为每个场景执行所有这些步骤可能很乏味。

一种解决方案可能是在一个给定的步骤中指定所有这些(假设我已准备好测试功能 X)。但是,在阅读功能步骤时,它并不是很精确。

这就是为什么我想知道步骤定义是否可以在功能范围内使用。我会使用这样的东西:

特征:我的特征

Obvious feature description here.

Given I have done something
And something else
And the last thing

场景:Y 验证

When I type X
Then I should see Y

场景:Z 验证

When I type X
Then I should see Z

关于这个:

特征:我的特征

Obvious feature description here.

场景:Y 验证

Given I have done something
And something else
And the last thing
When I type X
Then I should see Y

场景:Z 验证

Given I have done something
And something else
And the last thing
When I type X
Then I should see Z

欢迎任何解决方案,但我希望在阅读 .feature 文件时可以理解一些内容,而不必深入研究代码。

谢谢

【问题讨论】:

    标签: specflow


    【解决方案1】:

    Gherkin 是一种用于编写功能文件的语言,可以轻松解决您的问题。它称为背景,是在文件中的每个场景之前执行的几个步骤。

    查看此 wiki 页面了解更多信息; https://github.com/cucumber/cucumber/wiki/Background

    【讨论】:

    • 正是我需要的。奇怪的是,我没有看到我查看的示例中使用的背景。虽然它在文档中。谢谢!
    【解决方案2】:

    当使用背景标签时,您的场景和功能看起来或多或少是这样的:

    Feature: My feature
         As a person
         I want to do something
         So that something can happen
    
    Background: My Background
    Given I have done something
    And something else
    And the last thing
    
    Scenario: Y validation
          When I type X
          Then I should see Y
    
    Scenario: Z validation
          When I type X
          Then I should see Z
    

    【讨论】:

      猜你喜欢
      • 2011-07-10
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 2020-08-19
      • 2011-07-16
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多