Run a specific scenario from example table in BDD

75 views Asked by At

i have the below scenario in BDD frame work.

Scenario Outline: Addition of many numbers
  Given I have '<num1>' and '<num2>'
  When I add them
  Then The result must be '<total>'

  Examples:
    | num1 | num2 | total |
    | 1    | 1    | 2     |
    | 11   | 31   | 42    |
    | 21   | 41   | 62    |
    | 31   | 51   | 82    |

i can run this using --name Addition of many numbers which will execute all the 4 examples. but i want to execute only the 2nd example | 11 | 31 | 42 | How can i do this?

i tried --name Addition of many numbers [email protected] which doesnt work

1

There are 1 answers

0
sashkins On

You can do it by specifying the line number after the .feature filename:

behave your_feature.feature:line_number

From 'behave --help':

positional arguments:
paths: Feature directory, file or file location (FILE:LINE).

So if you have a feature like the following, you should run behave your_feature.feature:11 to run the 2nd example only (note that the line numbers start with 1)



  Feature: Addition

  Scenario Outline: Addition of many numbers

    Given I have '<num1>' and '<num2>'
    When I add them
    Then The result must be '<total>'
    Examples:
      | num1 | num2 | total |
      | 1    | 1    | 2     |
      | 11   | 31   | 42    |
      | 21   | 41   | 62    |
      | 31   | 51   | 82    |