gpt4 book ai didi

javascript - Gherkin - 维持场景之间的状态

转载 作者:行者123 更新时间:2023-12-02 14:49:09 25 4
gpt4 key购买 nike

尽管我已经编写单元测试 20 多年了,但我对 Gherkin 还很陌生,并且接到的任务是为 .feature 文件实现一个故事,该文件可简化为如下内容:

Scenario: a
Given that the app is open
When I open a certain dialog
Then it has a thing somewhere

Scenario: b
Given that the dialog from 'a' is open...

# Imagine here a long chain of scenarios, each depending on the previous

Scenario: n
Given that the previous 'n' steps have all completed....

也就是说,一长串场景,每个场景都取决于其前任配置的系统状态。

对于习惯于单元测试的人来说,这感觉不太好——但这些场景不会被拆分和单独运行。

这里的最佳实践是什么?

我应该重写一个很长的场景吗?

我已经使用“页面对象”将大部分代码排除在步骤定义之外 - 我是否应该将这些步骤编码为单个调用,以便可以在以后的场景中重复使用?

我正在 Javascript 中运行 Cucumber。

最佳答案

首先,警告:

对于大多数测试(我所说的大多数是指 99.9% 的时间),您不应该继续前一个场景,因为如果一个场景在您的功能中失败,更多的东西会崩溃,因为你试图将它们串在一起。

然后是我的回答:

根据您是否尝试对之后的所有场景进行设置(在同一功能内),或者是否要多次重复使用第一个场景(在单独的功能中),您可以执行以下两种操作之一事情。

  1. 将第一个场景设为背景
  2. 将第一个场景制作为步骤定义,以便在多个功能文件中使用

第一个:

Background:
Given that the app is open
When I open a certain dialog
Then it has a thing somewhere

Scenario: a
Given that the dialog from 'a' is open...

请记住,当您将其用作背景时,它将用于该功能中的以下所有场景。

第二个:

Scenario: a
Given that the app is open
When I open a certain dialog
Then it has a thing somewhere

Scenario: b
Given I have opened the dialogue from a
And the '<DialogFromA>' dialog is open...

关于javascript - Gherkin - 维持场景之间的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36334866/

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