1
votes

Should I use assert in any BDD steps other than in then steps?

I am attempting to understand how to use Specflow to describe "changing a user profile".

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  

The second given step And I can see a list of users should have an assert in the implementation, I think?

2

2 Answers

0
votes

I don't think And I can see a list of users is a valid "Given" step. If there are situations where you might be at the roles page and not see a list of users, than whatever situation is causing you to see the list should be specified as a "Given" step, but if you would expect to always see a list of users, then it doesn't need to be a "Given" step.

That is, if you should always see the list of users, you should have two tests:

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.

or, if there are scenarios where you might not see a list of users, that's a separate "Given":

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.

Since the first test passes, in the second test you can assume that you see the list of users.

0
votes

Remember to specify the WHAT not the HOW and to use concrete examples.

Scenario: Admin can edit existing user's profile details

    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. create these profiles in the db (or assert that they are already present in db, if not working from a clean setup).
  2. everything you need to get to do get to editing the profile of Andy (logging in, navigating etc)
  3. drive UI to change the name
  4. drive UI to user summary, extract data from ui and assert content meets expectations.