【问题标题】:SpecFlow ScenarioOutline 'losing' example namesSpecFlow ScenarioOutline“丢失”示例名称
【发布时间】:2013-02-03 08:49:30
【问题描述】:

我正在尝试从我的 specflow 功能文件生成文档(pdf 格式)。我正在使用 Nuget 上的 gerkin 库来解析文件。

我有一些场景大纲,每个场景大纲有 2 个示例表(根据 Cucumber 书完全可以):

Scenario Outline: My scenario

Given "<this>" first value
When I enter some second "<value>"
Then the result must be equal to "<expected result>"

Examples: Some first list of values // My example name
| this | value | expected result |
| 0    | 1     | 2               |

Examples: Some second list of values  // My example name
| this | value | expected result |
| A    | B     | C               |

我遇到的问题是当您解析此文件时。您可以访问所有给定的示例,但只能访问一个示例名称。因此,当您构建文档时,您无法判断它是来自第一组示例还是来自第二组示例。我注意到像“Pickles”这样的其他工具也有同样的问题。

这是一些尝试获取每个示例名称的代码:

foreach( var feature in file.Feature.FeatureElements )
{
    var example = ( ( ScenarioOutline ) ( x ) ).Example;

    // this value always remain the same and is incorrect according to my feature file.
    var exampleName = example.Name != exampleName
}

我认为问题可能出在 SpecFlow 库本身,而不是用于解析的 gerkin 库 - NUnit 在创建测试用例时似乎也看不到第二个示例名称。

以前有人处理过吗?

PS:有人请标记scenariooutline。它与场景不同。

【问题讨论】:

    标签: documentation specflow gherkin scenarios


    【解决方案1】:

    Specflow 不支持场景大纲中的多个示例块。为什么不把你的第二个例子列表放到第一个?即

    Examples:
    | this | value | expected result |
    | 0    | 1     | 2               |
    | A    | B     | C               |
    

    如果您明确希望为您可以拥有的不同类型的输入(即所有数字或所有字符)提供不同的测试场景,那么我将创建两个不同的场景大纲,例如

    Scenario Outline: Calculate the result for numeric input
    
    Given "<this>" first value
    When I enter some second "<value>"
    Then the result must be equal to "<expected result>"
    
    Examples:
    | this | value | expected result |
    | 0    | 1     | 2               |
    

    还有:

    场景大纲:计算字母输入的结果

    Given "<this>" first value
    When I enter some second "<value>"
    Then the result must be equal to "<expected result>"
    
    Examples:
    | this | value | expected result |
    | A    | B     | C               |
    

    【讨论】:

      猜你喜欢
      • 2022-07-08
      • 1970-01-01
      • 2020-06-07
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-02
      相关资源
      最近更新 更多