2013-05-20 38 views
1

我应该在then步骤以外的任何BDD步骤中使用assert吗?在BDD步骤中使用断言

我试图了解如何使用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应该在实现中有一个断言,我想呢?

回答

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. 

因为第一测试通过,在第二次测试,你可以假设你看到用户列表。

+0

我不知道我能做到这一点,但如果我想同时运行测试,因为这些都是端到端的和缓慢的,另外,在执行功能的文件时确实specflow遵循从上到下依次是? –

+0

依靠测试的执行顺序决不是一个好主意。但这也应该没有关系 - 大概如果名单列表应该出现而不是,第二个测试将会中断(以某种方式可能无法说明问题是什么) - 但是第一个测试(偶数如果它第二次运行)将以有用的方式失败。在并行运行测试方面,请查看SpecRun(http://www.specrun.com/)。 –

+0

对于'鉴于我是管理员',我应该采取一些行动,让我进入管理员角色,而不是验证我是管理员? –

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. 创建的数据库这些配置文件(或声称,他们是在数据库已经存在,如果不从一个干净的安装工作)。
  2. 你需要去便得到编辑安迪的个人资料(登录,导航等)
  3. 驱动的用户界面,从界面更改名称
  4. 驱动UI用户总结,提取数据并断言内容符合一切期望。