10

我有这个功能文件:

Scenario Outline: Example
    Given I am a user
    When I enter <x> as an amount
    Then the result should be <result>
    Examples:
        | x | result |
        | 3 | 3      |
        | 1 | 1      |

我的问题是,运行后,每个示例都标记为variant #

有没有办法命名每个示例行实际测试的内容,以便在报告中,我们更好地了解测试的内容,而不仅仅是:

Scenario: Example, Variant 0
Scenario: Example, Variant 1
Scenario: Example, Variant 2

我正在努力帮助我们的测试人员获得更有意义的报告;他们编写多个示例通常是有原因的,并且他们希望以某种方式显示该示例的原因。

4

1 回答 1

13

正如 SpecFlow Scenario Outlines文档所说:

Gherkin 语法并不强制所有示例列在场景大纲中都具有匹配的占位符,您甚至可以在示例集中引入任意列以提高测试方法名称的可读性

因此,您可以在“示例”表中引入任意列,以简洁地描述测试的意图,例如

Scenario Outline: Example
    Given I am a user
    When I enter <x> as an amount
    Then the result should be <result>
    Examples:
        | example description   | x | result |
        | Example Description 1 | 3 | 3      |
        | Example Description 2 | 1 | 1      |

这将导致以下测试名称:

Example_ExampleDescription1
Example_ExampleDescription2
于 2014-02-21T23:11:48.630 回答