我已经开始使用 Cucumber 编写 BDD 测试来匹配我的应用程序的业务用例。它基于区块链,因此测试中的每个用户都在运行应用程序的一个实例。这也意味着每次测试都相当繁重,95%的测试时间都在准备阶段。
当我编写测试时,我发现我开始重复自己,并且早期的功能似乎变得多余。
一种业务流程是:
用户1保存一条新消息
用户2编辑消息
User1 验证编辑
用户1取消消息
用户2确认取消
这分为新建/编辑/取消功能。
最初,我从“新建”和“编辑”功能文件开始,如下所示:
新的
Feature: a new message is added
Scenario: a user adds a new message
Given there is a user called User1
And there is a user called User2
When User1 creates a new message with id 1234
Then User2 should see the message with id 1234
编辑
Feature: Editing a message
Scenario: A User edits a message
Given there is a user called User1
And there is a user called User2
When User1 creates a new message with id 1234
And User2 adds the location US to the message
Then User1 should see the location US on the message
但现在我进入取消部分,我意识到为了正确测试取消,系统需要编辑消息,这意味着我需要完成新建和编辑功能以使消息进入正确的状态。
这将使取消看起来像这样,然后开始变得相当冗长:
取消
Feature: Cancelling a message
Scenario: A User cancels a message
Given there is a user called User1
And there is a user called User2
When User1 creates a new message with id 1234
And User2 adds the location US to the message
And User1 cancels the message
Then User2 should see status Cancelled on the message
我可以这样写取消:
Feature: Cancelling a message
Scenario: A User cancels a message
Given there is a message with id 1234
And User1 cancels the message
Then User2 should see status Cancelled on the message
作为一项功能,读起来相当不错,但是,我现在必须为“有一条 id 1234 的消息”编写一个步骤定义,该定义可以执行“编辑”功能正在执行的所有操作。
正如在开始时提到的,这些测试中的设置占用了 95% 的测试时间,因此理想情况下,我希望将这些作为一系列步骤一起运行,而不是从每个功能的新鲜开始。例如
进行一次设置
创建新消息
编辑消息
取消留言
是否可以将场景或功能链接在一起并重用前一个场景或功能的系统状态?
还是每次都必须从头开始启动系统?
调用构成“编辑”功能的所有其他步骤/方法的步骤定义是否是“取消”的正确方法,还是应该编写大量 And 语句?
波斯汪
jeck猫
相关分类