gpt4 book ai didi

bdd - Gherkin "OR"使用 BDD 减少重复的语法

转载 作者:行者123 更新时间:2023-12-04 13:04:28 24 4
gpt4 key购买 nike

有谁知道实现这一目标的方法,或者他们认为这是一个好主意。在 Gherkin 中使用 OR 样式语法以减少重复但保持人类可读性(希望如此)。我正在考虑使用多个 OR 语句的每个组合扩展子句组合的情况。例如

Scenario: TestCopy
Given Some text is selected
When The user presses Ctrl + C
OR the user right clicks and selects copy
OR the user selects Edit + Copy
Then the text is copied to the clipboard

这将作为 3 个测试运行,每个测试具有相同的给定,然后使用 OR 集中的一个 When。我想这可以通过使用带有 When 子句占位符的模板来实现,但我认为这更具可读性,并且可以允许在 Given 中使用 OR 来生成 n x m 测试。使用大纲,您仍然需要 n x m 行。
  • 有没有更好的方法来做到这一点
  • 显式复制和粘贴是更好的做法吗(我认为维护可能会变得困惑)
  • 其他框架是否支持这一点(我认为使用 FIT 您可以编写自定义表,但这似乎是开销)

  • 谢谢。

    最佳答案

    您可以使用 Scenario Outlines: 从一个场景生成多个测试

    Scenario Outline: TestCopy
    Given Some text is selected
    When <Copy operation executed>
    Then the text is copied to the clipboard

    Examples:
    | Copy operation executed |
    | The user presses Ctrl + C |
    | the user right clicks and selects copy |
    | the user selects Edit + Copy |

    Scenario Outline您基本上创建了一个模板,其中填写了提供的 Examples .
    对于上面的示例,Specflow 将生成 3 个具有相同 Given 的测试。和 Then和 3 个不同的 When年代:
    When The user presses Ctrl + C
    When the user right clicks and selects copy
    When the user selects Edit + Copy

    关于bdd - Gherkin "OR"使用 BDD 减少重复的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9093872/

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