如何多次运行小黄瓜场景

时间:2013-06-26 16:11:06

标签: c# specflow 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 个答案:

答案 0 :(得分:2)

在您当前的功能中,您写道:

Given I want to monitor start-up performances for run '<id>'

当您在“给定”之后使用“我想要”时,您应该使用“然后”,因为您期待结果。

还有以下内容:

Then I want to log those data

与之前的Given非常相似,即您想获取日志数据。

我将你的场景改写为:

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

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

答案 1 :(得分:1)

我不确定这是“测试”。

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

所以我希望看到更像

的东西
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?,它可能会帮助您构建未来的场景。 : - )

答案 2 :(得分:0)

你是对的,这不只是一个测试,它是我们每晚运行的性能测试之一,以确保解决方案的稳定性。所以重点是获取数据而不是看绿色成功按钮:)

如果specflow不是最佳解决方案,哪种工具可以更好?

该软件的设计不允许我使用“当我运行程序3次”时,遗憾的是......我不想只重复同一行3次。

无论如何,我使用了场景大纲并定义了我的步骤以依赖于示例。然后,如果有人想要更改运行次数,他所要做的就是在示例中添加更多行。

我正在寻找循环语句,因为我是这些技术的初学者。对于第一种情况,这也不是最好的任务:)

谢谢!

PS:这是场景

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  |
相关问题