首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有效的BDD方案步骤?给定-> When -> Then -> When

有效的BDD方案步骤?给定-> When -> Then -> When
EN

Stack Overflow用户
提问于 2010-09-01 17:09:58
回答 3查看 1.4K关注 0票数 1

如果我定义了以下步骤,这是有效的场景吗?我觉得这是一种味道。

代码语言:javascript
复制
Scenario: Change users status
   Given I have the following users exist:
        | code | status   |
        | u1   | active   |
        | u2   | inactive |
        | u3   | active   |
     And the status filter is "active"
    When I update "u1" to "inactive" 
    Then I should see the following users:
        | code |
        | u3   |
    When I change status filter to "inactive"
    Then I should see the following users:
        | code |
        | u1   |
        | u2   |
EN

回答 3

Stack Overflow用户

发布于 2011-11-25 17:10:54

Liz对系统功能的描述是正确的。我还建议在场景中只使用一个。因为每个场景(我认为)都应该验证系统在发生某些事情时从给定的状态转换到随后的状态。

在这种情况下,我还建议使用两种不同的功能。其中一个功能是关于你的应用程序可以改变用户状态(激活/停用):

代码语言:javascript
复制
Feature: Changing user status

Scenario: Deactivating user
   Given following users exist:
        | code | status   |
        | u1   | active   |
        | u2   | inactive |
        | u3   | active   |
    When user u1 is deactivated
    Then following users exist:
        | code | status   |
        | u1   | inactive |
        | u2   | inactive |
        | u3   | active   |

另一个功能是你可以根据状态过滤用户:

代码语言:javascript
复制
Feature: Filtering users

Scenario: Filtering active users
   Given following users exist:
        | code | status   |
        | u1   | active   |
        | u2   | inactive |
        | u3   | active   |
    When I filter for active users
    Then I should see the following users:
        | code |
        | u1   |
        | u3   |

Scenario: Filtering inactive users
   Given following users exist:
        | code | status   |
        | u1   | active   |
        | u2   | inactive |
        | u3   | active   |
    When I filter for inactive users
    Then I should see the following users:
        | code |
        | u2   |

在这种情况下,当其中一个场景被破坏时,您将知道原因。它要么没有改变用户的状态,要么没有正确地过滤他们。您知道您的应用程序中的哪个功能被破坏了。

票数 6
EN

Stack Overflow用户

发布于 2010-09-02 01:23:01

你用相当代码驱动的术语来描述它,但除此之外,它是一个有效的场景。

如果你想让它变得更好,你可以根据系统的功能来描述它,用用户可能用来描述他们正在做什么的语言:

代码语言:javascript
复制
Scenario: Change users status
   Given these users exist:
        | code | status   |
        | u1   | active   |
        | u2   | inactive |
        | u3   | active   |
    And we filter for active users
    When I disable user u1
    Then I should see the following users:
        | code |
        | u3   |
    When we filter for inactive users
    Then I should see the following users:
        | code |
        | u1   |
        | u2   |

您还可以使用更典型的用户名,以便阅读它的人一眼就能理解这些名称代表什么(Lunivore、Soe、Jon而不是u1和u2)。

差别不是很大。你认为什么是难闻的气味?只是语言的问题吗?

票数 4
EN

Stack Overflow用户

发布于 2014-05-24 21:58:56

通常,只有一个“when”步骤是好的,因为这是您实际测试的内容。然而,有时我发现指定整个用例也很有用,这些用例可能包括几个相互依赖的then和when步骤。例如:

代码语言:javascript
复制
 when a new user registers
 then the user receives an email confirmation
 when the email confirmation is confirmed by the user
 then the user is registered 

然而,在您的示例中,您确实应该编写两个测试,因为您实际上测试了两个不同的功能,它们也不是直接相互依赖的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3616499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档