大约一年前使用过 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/