Question

So in my application I have grid with a list of all users registered to site. Now I would like to test it using specflow and WatiN.

I came up with following scenario:

Scenario: List of users
    Given I am logged in as "Admin" user
    And There exists following users
        | Username | First name | Last Name | Registration date |
        | alice    | Alice      | LAlice    | 2013-10-28        |
        | bob      | Bob        | LBob      | 2013-10-27        |
    When I go to all users page
    Then There should be following users in table
        | Username | First name | Last Name | Registration date |
        | alice    | Alice      | LAlice    | 2013-10-28        |
        | bob      | Bob        | LBob      | 2013-10-27        |

The problem is that this table is duplicated across steps and I am not sure if this is the right way. Is there a better way to test if data is loaded into grid?

Was it helpful?

Solution 2

To check I understand the problem correctly, your concern is that you have repeated the definition of the table in the Given and Then steps of one scenario (i.e. you aren't running 100 similar scenarios that all require the same table set up).

It looks like what you have is fine.

Consider what would happen if the UI required a small amount of data transformation. e.g.

Given I am logged in as "Admin" user
And There exists following users
    | Username | First name | Last Name | Registration date |
    | alice    | Alice      | Wonderland| 2013-10-28        |
    | bob      | Bobby      | Tables    | 2013-10-27        |
When I go to all users page
Then There should be following users in table
    | Username | Full Name        | Registration date |
    | alice    | Alice Wonderland | 2013-10-28        |
    | bob      | Bobby Tables     | 2013-10-27        |

This scenario is clear and you couldn't save any space here.

By repeating the table exactly, as you have done, you are making it clear in your test/living documentation that what you see on the page should exactly match the data representation in memory. This is worth expressing in the test.

Other options that could save some space:

Given I am logged in as "Admin" user
And there exists the following users
    | Username | First name | Last Name | Registration date |
    | alice    | Alice      | LAlice    | 2013-10-28        |
    | bob      | Bob        | LBob      | 2013-10-27        |
When I go to all users page
Then I should be able to see all the users

This is not very clear, and requires setting up the Then step to either share data with the Given step, or to actually query the mock data context itself (a very bad plan, because the test could pass for the wrong reason).

If you're asking if there is anything line C++'s #define keyword to set up a reusable multiline string const - there isn't, to my knowledge, and if there were, you shouldn't use it for the reasons of clarity above.

In conclusion - I like your test just the way it is. :)

---- edit ---- Afterthought:

Tests should fail for exactly one reason. Arguably, your test is testing "the table data is exactly right."

But sometimes you just want to test something simpler. E.g.

Then user 'alice' should appear in the users table

OTHER TIPS

You could approach this test in a different way, although whilst the following approach will remove the duplication of data from your scenario, it is not necessarily more efficient as the test will check each user individually.

What you could do is re-write the test to make use of Specflow's Scenario Outline feature. Then if you were to rewrite your Scenario as following, you would only have to define the user data once:

Scenario Outline: List of users
 Given I am logged in as "Admin" user
 And There exists <Username> with <First name> <Last Name> and <Registration date>
 When I go to all users page
 Then There should be <Username> with <First name> <Last Name> and <Registration date>

   examples:
    | Username | First name | Last Name | Registration date |
    | alice    | Alice      | LAlice    | 2013-10-28        |
    | bob      | Bob        | LBob      | 2013-10-27        |
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top