在BDD步骤中使用assert

时间:2013-05-20 18:16:40

标签: bdd specflow

我应该在除assert步骤之外的任何BDD步骤中使用then吗?

我试图了解如何使用Specflow来描述“更改用户个人资料”。

SCENARIO I can change a user  
Given I am at the roles page  
And I can see a list of users  
When I click a user's name  
| field    | value    |  
| User     | John Doe |  
And I change the user's name  
| field    | value    |  
| User     | Jane Doe |  
And I click the 'modify' button  
Then I should the user updated in the list  

我认为第二个给定步骤And I can see a list of users应该在实现中有一个断言?

2 个答案:

答案 0 :(得分:0)

我认为And I can see a list of users不是有效的“给定”步骤。如果在某些情况下您可能位于角色页面而没有看到用户列表,那么无论何种情况导致您看到列表都应指定为“给定”步骤,但是如果您希望始终看到列表用户,那么它不需要是“给定”步骤。

也就是说,如果你应该总是看到用户列表,你应该有两个测试:

Given I am an admin
When I am at the roles page
Then I should see a list of users

Given I am an admin
And I am at the roles page
When I click a user's name
... etc.

或者,如果在某些情况下您可能看不到用户列表,那就是单独的“给定”:

Given I am an admin
And some users exist
When I am at the roles page
Then I should see a list of users

Given I am an admin
And some users exist
And I am at the roles page
When I click a user's name
... etc.

自第一次测试通过以来,在第二次测试中,您可以假设您看到了用户列表。

答案 1 :(得分:0)

请记住指定什么不是如何,并使用具体的例子。

  

场景:管理员可以编辑现有用户的个人资料详情

    Given user profiles exist
     | Name | Age |
     | Andy | 21  |
     | Sarah| 22  |
    And Admin has started editing Andy's profile
    When 'Andy's profile is changed to - name:'Bob' age:'99'
    Then the Admin's summary of users includes
     | Name  | Age|
     | Bob   | 99 | 
     | Sarah | 22 |
  1. 在db中创建这些配置文件(或断言它们已经存在于db中,如果不是从干净的设置中工作)。
  2. 您需要做的一切都可以编辑Andy的个人资料(登录,导航等)
  3. 驱动用户界面更改名称
  4. 将UI驱动到用户摘要,从ui中提取数据并断言内容符合预期。