如何多次运行Gherkin场景

4
我写了这个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

欢呼!
3个回答

2
我不确定这是一个“测试”。
它肯定是一个捕获数据的脚本,但测试也有一个条件,在其中有一个必须验证的值或状态。
因此,我希望看到更像这样的东西。
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的这个领域到底是谁的?,它可能会帮助你构建未来的场景。 :-)

2
在您当前的功能中,您写道:
Given I want to monitor start-up performances for run '<id>'

由于您在“Given”之后使用了“I want”,因此应改为使用“Then”,因为您期望有一个结果。

另外,以下是:

Then I want to log those data

这段文本与之前的是相似的,即你想获取日志数据。

我会把你的场景重新表述一下:

Feature: Test my program startup time

Background:
  Given the system is activated with a license
  And I have a clean installation environment

Scenario Outline: Startup
  Given the system is ready to start
  When I perform test run '<id>'
  Then the system should start in less than 3 seconds
  And the system should generate log data for test run '<id>'

Examples: Run ID
    | id |
    | 1  |
    | 2  |
    | 3  |

此外,如果步骤为:

And I have a clean installation environment

明确清除CurrentPath并将配置文件设置为user_startup_performances.config,然后我可以摆脱:

And the user preferences file is user_startup_performances.config
And the CurrentPath directory is empty

这就是我在建议的重写中所做的事情。

0

你说得对,那不仅仅是一个测试,它是我们每晚运行的性能测试之一,以检查解决方案的稳定性。因此,重点更多地是获取数据而不是看到绿色的成功按钮 :)

如果SpecFlow不是最好的解决方案,哪个工具可能会更好呢?

软件设计不允许我使用“当我运行程序3次”这个选项,很遗憾...我也不想只是重复相同的行3次。

无论如何,我使用了一个场景大纲,并将我的步骤定义为依赖于示例。然后,如果有人想要更改运行次数,他只需要在示例中添加更多行即可。

我正在寻找一个循环语句,因为我是这些技术的初学者。这也不是一个适合第一个场景的最佳任务 :)

谢谢!!

附:这是场景

Feature: Test my program startup time

Background:
  Given my program is activated with a licence elite

Scenario Outline: 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 for run '<id>'
  Then I want to log those data

Examples: Run ID
    | id |
    | 1  |
    | 2  |
    | 3  |

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接