c# - 如何多次运行小 cucumber 场景

标签 c# specflow gherkin

我编写了这个 gherkin 功能,它运行良好。但是我的公司要求我能够在测试期间多次运行它。我们有一个控制服务器端的应用程序客户端,以模拟使用该软件的真人。 所以我的客户端被实例化一次并且必须运行 3 次这个场景。

是否有像我在这里可以使用的“for”语句?

Feature: Test program startup time

Background:
  Given my program is activated with a licence

Scenario: Startup
  Given I want to use a clean installation
  Given the user preferences file is user_startup_performances.config
  Given the CurrentPath directory is empty
  Given I want to monitor startup performances
  Then I want to log those data

干杯!

最佳答案

我不确定这是一个“测试”。

这绝对是一个捕获数据的脚本,但测试中也有一个条件,一个必须验证的值或状态。

所以我希望看到更像的东西

Given I set something up
And I setup something else
....
When I run the program
Then my startup time should be less than 1 second

但是,我确实理解您希望以一种简单一致的方式来运行此测试,虽然我认为 SpecFlow 可能不是实现您想要的目标的最佳方式,但您可能需要考虑您的测试粒度。例如,您可以将场景重写为

Given I ...
When I run the program
Then my startup time should be less than 1 second
When I run the program
Then my startup time should be less than 1 second
When I run the program
Then my startup time should be less than 1 second

现在您已经对其进行了三次测试。

或者你可以写成

Given I ...
When I run the program 3 times
Then my startup time should be less than 1 second

然后在你的 C# 中

[When("I run the program (\d+) times")]
public void WhenIRunTheProgramManyTimes(int count)
{
    for(int i=0; i++; i<count)
    WhenIRunTheProgram();
}

[When("I run the program")]
public void WhenIRunTheProgram()
{
   ....

另请查看 Dan North 的 Whose Domain is it anyway? ,它可能会帮助您构建 future 的场景。 :-)

关于c# - 如何多次运行小 cucumber 场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325243/

相关文章:

selenium - Gherkin 格式的测试场景需要什么级别的详细信息来支持自动化测试?

C#:静态 Guid 作为属性的参数

c# - SpecFlow:场景大纲示例

java - cucumber - Java - 标识符中的非 ASCII 字符

nunit - 执行 specflow 功能的顺序

.net - Specflow 或 BDDfy

cucumber - Gherkin 语法中的数组占位符

c# - 将 T 转换为 bool,反之亦然

c# - 我怎样才能真正执行这个?

C# Blazor 和数据绑定(bind)到 DateTime?