【发布时间】:2011-02-19 07:01:20
【问题描述】:
我遇到了这个问题Cucumber scenarios for extremely long work flow
现在我一直在为一长串的多部分表单步骤中的每一个编写孤立的场景。我有一个Background 部分,用于设置每个Scenario。但是现在当我运行整个功能时,黄瓜想为每个Scenario 重复Background。我想测试一个基于所有以前的Scenario。
这是我的功能的大致轮廓:
Feature: Submit a manuscript
In order to complete a manuscript submission
As a corresponding author
I want to complete the to-do list
Background:
Given I am logged in as "Steve"
And an article_submission "Testing Web Apps" exists
And "Steve" is a "Corresponding Author" for "Testing Web Apps"
And I am on the manuscript to-do list page for "Testing Web Apps"
Scenario: Steve suggests reviewers for his manuscript
...
Scenario: Steve completes the manuscript fees to-do item
...
Scenario: Steve wants to add Barbara as a co-author
...
Scenario: Steve uploads necessary files
...
Scenario: Steve edits the fees page and general information page
...
Scenario: Steve re-uploads the manuscript file
...
Scenario: Steve completes the Copyright Transfer
...
Scenario: Steve completes Author Responsibilities & Agreement
...
# These scenarios depend on all the previous ones having run
Scenario: Steve Completes submission
...
Scenario: Steve goes back and make changes
...
Scenario: Steve fills out payment page
有没有办法要求运行以前的场景?有没有办法只运行一次Background?
【问题讨论】:
-
我认为你可能会让自己变得比需要的更难。您作为场景列出的内容对我来说就像场景中的步骤一样。就像潘在您链接到的问题的答案中提到的那样,您的场景应该是自包含的,并且它们之间没有像这样的依赖关系。如果是我,我会将背景和场景折叠成一小部分(最后的 3 个可能会分别变成 1 个场景)并使用更高级别的步骤,例如“鉴于史蒂夫已完成稿件提交”并在以确保每个步骤都有效。
-
这些场景大部分是独立的。相信我,这些场景并不短。我已经有数百步了。将它们结合起来会使阅读变得更加困难,并且不那么独立。我已经尽可能地重构了将常用步骤移动到步骤定义文件中。我认为我真正需要的是一种在功能运行后冻结数据库,然后在下一个依赖功能之前加载它的方法。
-
我们的应用程序的工作方式是,作者需要一个很长的工作流程,然后是审稿人,然后是修订过程。每个工作流程都取决于前一个工作流程设置的条件。我已经有很多装置和工厂加载数据,但我需要的是一个同时创建所有模型的工厂。我不想每次需要测试功能 C 时都重复功能 A 和 B。
标签: ruby-on-rails ruby-on-rails-3 cucumber