Search code examples
c#specflow

How can I add different examples with different columns in specflow examples


The following code is my Scenario:


Scenario: TradeOrders

    Given Order 'SellOrder' Has Been Registerd
        | Side | Price | Amount | IsFillAndKill | ExpireTime                  |
        | 0    | 100   | 5      | false         | 2024-02-05 09:30:26.2080000 |


    And Order 'BuyOrder' Has Been Defined
        | Side  | Price   | Amount   | IsFillAndKill   | ExpireTime   |
        | <Buy> | <Price> | <Amount> | <IsFillAndKill> | <ExpireTime> |

    When I Register The Order 'BuyOrder'


    Then The following 'Trade' will be created
        | BuyOrderId   | SellOrderId   | Amount        | Price        |
        | <BuyOrderId> | <SellOrderId> | <TradeAmount> | <TradePrice> |

        
    And BuyOrder 'BuyOrder' Should Be Modified  like this
        | Side | Price | Amount | IsFillAndKill | ExpireTime                  |
        | 1    | 100   | 0      | false         | 2024-02-05 09:30:26.2080000 |



Examples:
    | Buy | Price | Amount | IsFillAndKill | ExpireTime                  |
    | 1   | 100   | 5      | false         | 2024-02-05 09:30:26.2080000 |


Examples:
    | <BuyOrderId> | <SellOrderId> | <TradeAmount> | <TradePrice> |
    | 1            | 2             | 5             | 100          |

I want to add some examples with different columns but I have faced with below error:

Severity Code Description Project File Line Suppression State Error Generation error: Message: The example sets must provide the same parameters.

I appreciate you in advance.


Solution

  • This is not supported in SpecFlow. Since both tables are used in the same scenario, they need to go in the same row. It makes for a wide table, but there isn't anything you can do about it. Second of all, you cannot have < or > tokens in the column headers.

    Examples:
        | Buy | Price | Amount | IsFillAndKill | ExpireTime                  | BuyOrderId | SellOrderId | TradeAmount | TradePrice |
        | 1   | 100   | 5      | false         | 2024-02-05 09:30:26.2080000 | 1          | 2           | 5           | 100        |
    

    You can also put spaces in the column headers so they are easier to read:

    Examples:
        | Buy | Price | Amount | Is Fill And Kill | Expire Time                  | Buy Order Id | Sell Order Id | Trade Amount | Trade Price |
        | 1   | 100   | 5      | false            | 2024-02-05 09:30:26.2080000  | 1            | 2             | 5            | 100         |
    

    The choice to include spaces in column headers is subjective. It is supported to aid readability, but feel free to omit spaces if this does not make the examples table easier to understand.