设计表单 Cucumber 场景的最佳 BDD 实践

发布于 2024-10-07 07:21:54 字数 563 浏览 0 评论 0原文

假设您有一个创建新用户的表单。 你如何编写你的 Cucumber 场景?

1.)

Given I am logged in as admin
When I create a new user
Then I should see "Successfully created user"

2.)

Given I am logged in as admin
When I go to Create new user
And I fill in "Name" with "Name111"
And I fill in "Password" with "Password111"
And I press "Create new user"
Then I should see "Successfully created user"

如果您选择 1.) 您在哪里记录用户的要求(用户应该有名称和密码)。我发现 BDD 与行为有关,但在某些时候,您和利益相关者必须指定用户应该具有哪些属性,不是吗?

我对 BDD 很陌生,所以我很感激任何建议......

Lets say you have a form which creates a new user.
How do you write your Cucumber scenario?

1.)

Given I am logged in as admin
When I create a new user
Then I should see "Successfully created user"

2.)

Given I am logged in as admin
When I go to Create new user
And I fill in "Name" with "Name111"
And I fill in "Password" with "Password111"
And I press "Create new user"
Then I should see "Successfully created user"

If you choose 1.) where do you document the requirements for a User (A user should have a name and a password). I see that BDD is about behavior but at some point you and the stakeholder have to specify which properties a user should have, don't you?

I'm very new to BDD so I appreciate any advise...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帝王念 2024-10-14 07:21:54

您应该阅读命令式场景与声明式场景。

——阿斯拉克。黄瓜的创造者。

You should read Imperative vs Declarative Scenarios.

--Aslak. Creator of Cucumber.

祁梦 2024-10-14 07:21:54

你写的场景水平相当低。除非您实际上正在生产要出售的安全登录功能,否则我会坚持使用满意的案例并对其余部分进行单元/手动测试。如果不这样做,您将创建如此多的场景,这将是维护的噩梦。

找出您正在创建的产品与所有类似产品的区别,然后将其作为场景的价值。然后它会看起来像这样:

Given Fred is logged in
When Fred <does something>
Then Fred should <get some really differentiating value>
And <something else happens>

坚持真正的高级功能,而不是基于低级表单的步骤。例如:

Given there is already a question on BDD and Cucumber
Given Peyote is logged in
When Peyote proposes a question on BDD and Cucumber
Then Peyote should see other questions on BDD and Cucumber.

有一个称为“页面范式”的概念,您可以在其中创建一个包含页面或屏幕可以执行的所有低级步骤的类。然后,您可以从较高级别的 Cucumber 步骤装置中调用页面上的这些低级别步骤。

您的企业将更多地参与此类场景。 BDD 的主要目的不是生成自动化测试,而是围绕场景进行对话,以便您可以在麻烦地实现代码之前找出哪里出了问题以及可以考虑哪些其他选项。自动化测试是一个很好的副产品。

对话以及通过对话获得的知识是 BDD 与 ATDD(验收测试驱动开发)的不同之处。这就是为什么我们使用“Example、Scenario、Given、When、Then、Context、Event、Outcome”等语言而不是“Test、SetUp、TearDown、Act、Arrange、Assert”等语言 - 所以我们可以用同一种语言与业务人员、BA 和测试人员讨论这些问题。

请参阅 Dan North 关于 Deliberate Discovery 的文章以及他的其余文章博客了解更多信息,祝 BDD 好运!

The scenarios you've written are fairly low level. Unless you're actually producing secure login functionality to sell, I'd stick to the happy case and unit / manual test the rest. If you don't, you'll create so many scenarios it'll be a maintenance nightmare.

Find out what differentiates the product you're creating from all the similar products, then target that as the value of the scenario. Then it will look like this:

Given Fred is logged in
When Fred <does something>
Then Fred should <get some really differentiating value>
And <something else happens>

Stick to the really high-level capabilities, rather than low-level form-based steps. For instance:

Given there is already a question on BDD and Cucumber
Given Peyote is logged in
When Peyote proposes a question on BDD and Cucumber
Then Peyote should see other questions on BDD and Cucumber.

There's a concept called the "Page Paradigm", in which you create a class with all the low-level steps that the page or screen can perform. You can then call those low-level steps on the page from within the higher-level Cucumber step fixtures.

Your business will be much more engaged with scenarios like this. The main purpose of BDD is not to produce automated tests, but to have conversations around the scenarios so that you can find out where you're going wrong and what other options you could consider before you go to the trouble of implementing the code. Automated tests are a nice by-product.

The conversations, and the learning you get by talking through them, are the things which make BDD different from ATDD (Acceptance Test Driven Development). That's why we use language like Example, Scenario, Given, When, Then, Context, Event, Outcome instead of Test, SetUp, TearDown, Act, Arrange, Assert - so we can talk about these with business, BAs and testers in the same language.

See Dan North's article on Deliberate Discovery and the rest of his blog for more, and good luck with the BDD!

枕头说它不想醒 2024-10-14 07:21:54

任何一个都会起作用。使用#1,您将创建一个步骤来处理表单的填写。我更喜欢 #1 和 #2 的混合,因为我经常使用场景大纲,例如:

Background: 
 Given the following users exist:
   | email             | password        |
   | [email protected]  | testpassword23  |
   | [email protected] | notthistime     |
   | [email protected] | welcomeback     |

  @login @authentication
  Scenario Outline: Authentication
     Given I am on the new user session page
     When I login with "<s_email>" and "<s_password>"
     And I press "Login"
     Then I should see "<s_message>"

  Examples:
    | s_email           | s_password       | s_message                      |
    | [email protected]  | testpassword23   | Signed in successfully         |
    | [email protected] | itriedreallyhard | Invalid email or password.     |
    | [email protected] | testpassword23   | Invalid email or password.     |

Either one will work. With #1 you would create a step to handel the filling in of the form. I prefer a hybrid of #1 and #2 because I use Scenario Outlines alot for example:

Background: 
 Given the following users exist:
   | email             | password        |
   | [email protected]  | testpassword23  |
   | [email protected] | notthistime     |
   | [email protected] | welcomeback     |

  @login @authentication
  Scenario Outline: Authentication
     Given I am on the new user session page
     When I login with "<s_email>" and "<s_password>"
     And I press "Login"
     Then I should see "<s_message>"

  Examples:
    | s_email           | s_password       | s_message                      |
    | [email protected]  | testpassword23   | Signed in successfully         |
    | [email protected] | itriedreallyhard | Invalid email or password.     |
    | [email protected] | testpassword23   | Invalid email or password.     |
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文