Search code examples
gobddgherkin

How can I execute a specific feature file before the execution of remaining feature files in goDog?


I have a few data setup before implementing the remaining test cases. I have grouped all the data setup required to be executed before the execution of test cases in a single feature file.

How can I make sure that this data setup feature file is executed before executing any other feature file in goDog framework?


Solution

  • As I understand your question, you're looking for a way to run some setup instructions prior to running your feature/scenario's. The problem is that scenario's and features are, by design, isolated. The way to ensure that something is executed prior to the scenario running is by defining a Background section. AFAIK you can't apply the same background across features. Scenario's are grouped per feature, and each feature can specify a Background that is executed before each scenario. I'd just copy-paste your setup stuff everywhere you need it:

    Background:
      Given I have the base data:
        | User | Status   | other fields |
        | Foo  | Active   | ...          |
        | Bar  | Disabled | ...          |
    

    If there's a ton of steps involved in your setup, you can define a single step that you expand to run all the "background" steps like so:

    Scenario: test something
    Given my test setup runs
    

    Then implement the my test setup runs like so:

    s.Step(`^my test setup runs$`, func() godog.Steps {
        return godog.Steps{
                       "user test data is loaded", 
                       "other things are set up",
                       "additional data is updated",
                       "update existing records",
                       "setup was successful",
                }
    })
    

    That ought to work.

    Of course, to avoid having to start each scenario with that Given my test setup runs, you can just start each feature file with:

    Background:
       Given my test setup runs
    

    That will ensure the setup is performed before each scenario. The upshot will be: 2 additional lines at the start of each feature file, and you're all set to go.