gpt4 book ai didi

c# - Specflow:为每个功能指定多个场景

转载 作者:太空狗 更新时间:2023-10-30 00:41:16 25 4
gpt4 key购买 nike

通过 SpecFlow 文档,我试图弄清楚我的看法是否错误。我想为每个功能指定几个完全不同的场景。

例如:

Feature: Serve coffee
Coffee should not be served until paid for
Coffee should not be served until the button has been pressed
If there is no coffee left then money should be refunded

Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1$
When I press the coffee button
Then I should be served a coffee

如果我想在“提供咖啡”功能中查看其他场景怎么办?比如已经付了钱但是5分钟没有按下按钮的场景。

有多个场景是否有意义,还是我应该使用场景大纲?

谢谢!

最佳答案

每个功能的多个场景都可以,只要它们在逻辑上位于同一区域即可。如果您试图解决不同的用例,我可能会建议将其作为一项新功能。在您的情况下,这两种情况看起来在同一功能下都非常适合。

Scenario Outline 类似于 NUnit 中的 TestCase,只有在相同的场景结构只需要采用不同的参数时才使用它。


SpecFlow github 站点有很好的场景大纲文档 here .我将在下面总结代码示例。

给定一个特征中的两个场景:

Scenario: eat 5 out of 12
Given there are 12 cucumbers
When I eat 5 cucumbers
Then I should have 7 cucumbers

Scenario: eat 5 out of 20
Given there are 20 cucumbers
When I eat 5 cucumbers
Then I should have 15 cucumbers

您可以使用大纲参数化重复部分:

Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers

Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |

此大纲将替换您尝试参数化的场景定义。

关于c# - Specflow:为每个功能指定多个场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21725881/

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