1

For a BDD, is it ok if I skip the given statement or convert a When to And statement?

1
  • 1
    Would be easier to answer this question, if you supplied a little context. What is your feature? What is your scenario? Why are you wondering whether the given should be skipped or not? What do you mean by "conver a When to And"? Can you update with some examples? Commented Dec 21, 2015 at 13:14

1 Answer 1

2

If your scenario requires no setup, then skipping the Given step is ok I think. I'm not sure it makes sense to skip any of the other steps, as the When is the action step and if you are not performing any action then what are you testing?

It is also possible to write steps which have no implementation if they make you scenarios more readable so you could have something like this:

Given a standard installation of the application When I open the app Then the app splash screen should be displayed 

The Given step might be empty here (if a standard installation is already performed by some setup and the additional setup is performed by other steps) but its inclusion makes the scenario make more sense. (This is not a great example I realise, but it hopefully conveys the point)

As for changing the When to an And, yes you can do this as this is the point of the And and the But keywords, to make the steps more readable. They effectively have the meaning of 'repeat whatever the current keyword is for this step as well' so and And after a When is the same as another When

Sign up to request clarification or add additional context in comments.

2 Comments

I agree with this. Having human readable tests is one of the great things about using the Gherkin syntax. If you need to have a Given step that has no code in it to achieve this then go for it. Just remember to put in a comment explaining why there is no implementation code in your step definition.
@alannichols yeah a comment explaining why is usually a good idea in these situations

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.