是否可以将某个功能重新用作另一个功能的"给定"?

Mic*_*dry 10 cucumber gherkin

是否可以将某个功能重新用作另一个功能的"给定"?

或者我正在尝试做一些我不应该做的事情

基本上我的功能看起来像:

Scenario: Creating a basic account with valid details (happy path)
  Given I am on the "signup" page
  And I enter all the right details #this is shortened of about 20 steps for your reading ease
  When I press the button labelled "Sign up"
  Then I should see the text "Thanks for signing up"
  And I should have an email from "confirmation@mysite.com" titled "Confirm your account Michael"
  And the database should contain a record for the user marked as unconfirmed

Scenario: Confirming account via email
  Given I have created a basic account
  When I open the confirmation email and visit the url to confirm the account
  Then I should be logged in
  And the database should contain a record for the user makred as confirmed
Run Code Online (Sandbox Code Playgroud)

我清除了每个功能后的数据库,因为它们都应该能够单独运行...

我是以错误的方式来做这件事的吗?

谢谢

Tod*_*obs 9

问题

您实际尝试的是重用场景.黄瓜不再支持此功能.

除了这种方法的其他问题之外,您的测试将更慢且相互依赖,因为您将:

  1. 通过浏览器推动帐户创建,以及
  2. 使所有测试都依赖于帐户创建测试传递.

不要那样做.

黄瓜之路

通常,您应该编写测试以独立工作,尽管您当然可以重用步骤定义.因此,在一般情况下,您可能希望添加共享步骤,例如:

  1. 鉴于用户帐户"测试用户"不存在
  2. 鉴于存在用户帐户"测试用户"

然后可以根据需要将其包含在您的方案中.这种方法的好处是这些步骤可以以编程方式创建或删除用户.

或者,如果您的大多数测试都在现有帐户上,请使用正确的用户设备设置默认数据集.对于您将测试帐户创建的有限子集,只需添加一个驱动用户删除的方案背景.