gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:10:43 24 4
gpt4 key购买 nike

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

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