gpt4 book ai didi

c# - Specflow 特征文件 - 可能有多行示例

转载 作者:行者123 更新时间:2023-11-30 21:41:20 25 4
gpt4 key购买 nike

我想知道在场景大纲中是否可以为参数名称添加一个新行例如

  Scenario Outline: Login
Given <I> <am> <on> <the> <Office> <Portal> <link>
When I have entered my CRM credentials and sign in
Then I will be logged in
Examples:
|I |am | on| the | //newline
|data|data |data|data|
|Office |Portal |link|
|data|data |data|data|

我认为不会,因为我不确定它如何区分两行。我需要这个的原因是针对具有大量参数(例如 25 个参数)的冗长场景。

最佳答案

这不可能。

文档Cucumber中有说明规范示例部分应该是一个具有单个标题行和所有其他包含数据的行的表格:

The table must have a header row corresponding to the variables in the Scenario Outline steps.

Each of the rows below will create a new Scenario, filling in the variable values.

技术部分。 Specflow 使用 Gherkin语言解析器,将特征文件解析为 AST(抽象语法树)。该解析器逐行读取输入文件行并为每一行生成标记。来自 TokenScanner源代码:

The scanner reads a gherkin doc (typically read from a .feature file) and creates a token for each line. The tokens are passed to the parser, which outputs an AST (Abstract Syntax Tree).

解析器然后一一读取标记并确定该标记与哪一种相关。当它找到示例行时,它会查找单个标题行(Examples_Definition),后跟示例。如果你会做这样的事情

    |I      |am     | on   | the |
|data |data |data |data |
|Office |Portal |link |
|data |data |data |

那么第三行将被视为单元格数量不正确的示例行。

实际上解析器如何能够理解您是否有简单的数据行或标题行?所有示例数据均表示为字符串。 A 和 OfficeI 列的完全有效值。好的,在此特定示例中,底部表定义部分有 3 列。但如果也有四列呢?

    |I      |am     | on   | the |
|data |data |data |data |
|Office |Portal |link | foo |
|data |data |data |data |

无法为解析器定义第二个标题行。

可读性。坦率地说,这样的多行表格对于人们来说是难以阅读的。将示例表底部和顶部的第三个场景大纲部分关联起来是非常困难的。但可读性是 Gherkin 和 Specflow 的主要特点。如果您必须为场景提供如此多的参数,请考虑重新设计您的测试。

关于c# - Specflow 特征文件 - 可能有多行示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43492378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com