ruby - Cucumber 场景是否应该包含特定的 UI 步骤?

标签 ruby testing cucumber automated-tests

大约一年前使用过 Cucumber,我习惯了这样编写场景。

Scenario: user tries to vote on a comment
  Given I have a post
  And I have a comment on that post
  And I am logged in as a different user
  And I am on the post page
  When I click on "upvote" within the "comment"
  Then the comment score should raise
  And the comment author should get points

然而最近我发现,自 Cucumber 1.1 以来,基本的步骤定义如

When I click on "upvote" within the "comment"

不再可用,因为它们被认为是一种不好的做法。我明白这有什么意义,但我不确定我现在应该将我的功能编写多抽象。

想到的例子。

When I upvote on a comment
Then the comment should get points

或不太抽象

Given I have a post with a comment
And I'm not the author
When I upvote on the comment
Then the comment author should get points

或者更不抽象

Given I have a post with a comment
And I'm not the author
When I upvote on the comment
Then the comment score should increase
And the comment author should get 1 point

或者在Given部分非常具体

Given I have a post with a comment
And I'm not the author
And I am on the page for that post
When I upvote on the comment
Then the comment score should increase
And the comment author should get 1 point

我知道这是一个偏好问题,但我试图在这里寻求一些最佳实践。指定场景的最佳方式是什么?

最佳答案

我喜欢制作更具声明性的场景,但不要太多以至于不清楚涉及 UI 的哪一部分。我认为 Cucumber 团队在试图阻止第一种风格时,有点走得太远了。

我想我最喜欢你的最后一个例子:Given 通常应该非常具体。

关于ruby - Cucumber 场景是否应该包含特定的 UI 步骤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8418030/

相关文章:

ruby-on-rails - Ruby/Rails 调试策略

java - 是否可以在站点生命周期内只运行 JaCoCo maven 插件?

jquery - 使用 capybara / cucumber 测试 jquery-file-upload

javascript - 在 Cucumber.js 中是否可以列出所有可用的步骤?

sql - Rails ActiveRecord 查询以匹配所有参数

ruby - 如何从其他 Ruby 脚本调用标准 Rakefile 中定义的 Rake 任务?

node.js/karma/end-to-end testing : failed to proxy/app/index. html(错误:connect ECONNREFUSED)

cucumber - 按行号范围运行 Cucumber 场景大纲

ruby - 从哈希值的 ruby​​ 数组中获取前 n 个元素

python - 可以在纯 Python 中加速这个循环吗?