gpt4 book ai didi

testing - 在一个小 cucumber 场景中有多组 Given/When/Then 是否可以

转载 作者:行者123 更新时间:2023-11-28 19:40:07 24 4
gpt4 key购买 nike

我正在 Gherkin 中编写验收测试,我想根据初始操作测试 Web 应用程序 UI 中的多项更改。这是一个例子:

        Scenario: Cancel editing a new text asset
Given the user "test_user@fakedomain.com" is logged in
When the user navigates to "/build/"
And the user clicks the "Sandbox" link
And the user inputs "Test story for canceling editing of a new text asset" for the "title" field
And the user inputs "Test User" for the "byline" field
And the user inputs "My summary, so exciting!" for the "summary" textarea
And the user clicks on "Untitled Section" in the section list
And the user clicks the "Text" icon in the "center" container
And the user inputs the following text in the rich text editor:
"""
Test text for asset. This is cool.
"""
And the user clicks the "cancel" button
Then the following text is not present:
"""
Test text for asset. This is cool.
"""
And the "Image" icon is present
And the "Text" icon is present
When the user refreshes the browser
And the user clicks on "Untitled Section" in the section list
Then the following text is not present:
"""
Test text for asset. This is cool.
"""
When the user opens the asset drawer
Then the following text is not present:
"""
Test text for asset. This is cool.
"""

请注意,有多组 When/Then 步骤,用于测试初始操作的响应。虽然大多数步骤的实现都忽略了 prefix 关键字,而且我很确定我可以让这个测试运行,但有没有更好的方法来测试不同的结果?使用相同的设置但不同的“Then”语句编写多个场景是否更好?

最佳答案

请记住,您应该一次只测试一个行为/功能。经验法则是您应该仅使用一个 When 步骤:

Given some state before action
And some other state before action
...
When only one action
Then assert correct output
And assert correct output
...

你看 - 只有一行 When,When 下面没有任何 And。如果您改用许多 When 步骤,则您创建的是测试脚本,而不是规范。您的测试将很难理解,并且您会注意到当底层实现发生变化时您添加了越来越多的步骤。

您还需要隐藏底层逻辑,因为您不想每次更改不相关的内容时都更改它。示例:

And the user inputs "My summary, so exciting!" for the "summary" textarea

如果将摘要字段从文本区域更改为输入类型会怎样?你必须改变场景(维护噩梦)或者让你的场景撒谎(比没有场景更糟糕)。你应该这样写:

When the user describes it as "so exciting!"

但是,整个场景的结构仍然很糟糕。问自己一个问题:我想检查什么?如果我是一个想要了解该功能的业务逻辑的人,我希望看到如下内容:

Scenario: Cancel editing a new text asset
Given I edit the Sandbox details with some data
When I cancel editing
Then Sandox details should be empty

就是这样!

如何实现?更深入地移动所有不相关的逻辑,使用 PageObject pattern等。阅读有关 Specification By Example 的信息

关于testing - 在一个小 cucumber 场景中有多组 Given/When/Then 是否可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19392492/

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