cucumber / godog

Cucumber for golang
MIT License
2.31k stars 253 forks source link

How can I make BeforeSuite steps configurable? #182

Open 0xmichalis opened 5 years ago

0xmichalis commented 5 years ago

I need to do something like the following:

BeforeSuite:
   Given my db runs at "{{DB_HOST}}"

Scenario: 
    Given I can reach my api at "{{API_HOST}}"
    When I make a request to get all gifts with label "{{GIFT_LABEL}}"
    Then I should get at least 1 gift back

Then in a BeforeSuite step I want to seed my database, then I can run different scenarios in parallel that depend on the seeded data. I need to have DB_HOST configurable to enable my tests to run across environments (eg. a db deployed locally is going to have a different hostname from a db deployed on Kubernetes).

l3pp4rd commented 5 years ago

Hi, read the godoc. If you wanted it as a background step in gherkin, then change it.

Though, your gherkin looks ugly with these environment variables, why it cannot just take it from the step as Given my production database is running the step could read production as an argument, translate it to DB_HOST use the production database name and work on it.

0xmichalis commented 5 years ago

@l3pp4rd the only inputs to the test are the variables passed through the arguments which makes it easier to reason about the actual requirements needed for the test to run. If I start mapping a word in a step with a source of inputs that I need to get in my tests via a different way, eg. environment variables then the test is more complicated to setup and run across all envs because now apart from setting up the features files appropriately I need to: