2
votes

I'm writing a Scenario Outline in Specflow for Visual Studio. The objective is to test a Person Name comparer feature, in order to choose the best name between the two.

In my case, I have properties that belong to the names and properties external to them, which belong to the Person entity. The comparison flow is mad in two parts: first I check the properties of the persons (owners of the names) to decide and if that doesn't yield me a result (meaning their properties are the same) then I check the names' properties. I've written separate tests for the names' properties comparison, so in this test I only care about the Person properties and the relation between the names - which can be: Name1 < Name2, Name1 > Name2 or Name1 ≡ Name2.

By now I have written a scenario outline for each of those three cases, since I need to run each of the parameters in my Examples table once for each of those cases.

The code looks something like this:

Scenario Outline: Comparing names
    Given I have a first name <name1>
    And the first person has properties <properties1>
    And I have a second name <name2>
    And the second person has properties <properties2>
    When I choose the best name
    Then the best name should be <best name>

 Examples:
 | properties1                       | properties2       |
 | FirstName:"Carlos"                | FirstName:"Johny" |
 | LastName:"Smith"                  | FirstName:"Johny" |
 | FirstName:"John",LastName:"Smith" | LastName:"Smith"  |

Now in place of the names, I wrote this 3 times, one time for each case of the relation between the names, where I have the names hard-coded on the scenario.

Ideally, I would like to have a table of tables to be able to have a primary parameter that is ran with every line of the table.

Any idea how to implement that without having three different Scenario Outlines?

1
Without some more information about what "{properties}" contains, I'm afraid we cannot answer your question.Greg Burghardt
You're right, added specifics.Josef Ginerman
Can you post what you expect <best name> to be?Greg Burghardt
And what <name1> and <name2> as wellGreg Burghardt

1 Answers

1
votes

A SpecFlow table for creating each person might be the ideal solution. This allows you to pass values for each name, or a null value:

Scenario Outline: Comparing names
    Given I have a first name <name1>
    And the first person has properties:
        | Field      | Value          |
        | First Name | <first name 1> |
        | Last Name  | <last name 1>  |
    And I have a second name <name2>
    And the second person has properties:
        | Field      | Value          |
        | First Name | <first name 2> |
        | Last Name  | <last name 2>  |
    When I choose the best name
    Then the best name should be <best name>

Examples:
    | name1 | first name 1 | last name 1 | first name 2 | last name 2| best name |
    | X     | Carlos       |             | Johnny       |            | X         |
    | X     |              | Smith       | Johnny       |            | X         |
    | X     | John         | Smith       |              | Smith      | X         |

The advantage of this approach is you can expand the properties you set on each person.