Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber: Scenario Outline reusing examples table

I have a few tests like below:

Scenario Outline: Add two numebrs
  Given two numbers <number_1> and <number_2>
  When I add them
  Then Result is <number_3>

  Examples:
    |number_1|number_2|number_3|
    |2       |3       |5       |
    |1       |2       |3       |

Scenario Outline: Update two numebrs
  Given two numbers <number_1> and <number_2>
  When I update them
  Then Result is <number_3>

  Examples:
    |number_1|number_2|number_3|
    |2       |3       |5       |
    |1       |2       |3       |

For each test I should add the same table Examples.

Is any way to extract this table to use the same one for all tests?

like image 463
fashuser Avatar asked Mar 03 '26 11:03

fashuser


1 Answers

The easiest solution that comes to my mind is combining both scenarios, extracting details to the examples table. So it would look like:

| number_1 | number_2 | operation | result |

You have another possibility.

Scenario: Add two numebrs
Given I have the matrix of numbers
When I add them
Then I would have the resulting vector.

Scenario: Update two numebrs
Given I have the matrix of numbers
When I update them
Then I would have the resulting vector.

Where "the matrix of numbers" and "the resulting vector" go to step defs file.

like image 188
Ivan Avatar answered Mar 06 '26 00:03

Ivan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!