Building Up The Scenarios

So we have paragraphs of BDD sentences, and we  call these Scenarios.   

I am going to introduce some rules to a scenario.   These are, like everything else, quite simple to follow and understand (I hope).

Each Scenario can be just one sentence or as many as you want.  A Scenario can be a simple Given, When, Then.

When I Click On Button "X"   

This is COMPLETELY acceptable as a scenario!   You don't have any prerequisites, and don't expect any results.  Or you can take this to the other extreme...

When I Click On Button "A" 

When I Click On Button "B" 

When I Click On Button "C" 

When I Click On Button "D" 

When I Click On Button "E" 

I read 5 Whens, and I will start at the top, and follow each When in the order they are written.    So you can have as many Givens, Whens and Then's in a Scenario.

There is one rule to remember!  Givens are looked at before Whens, which are completed before Then's.

So if you had the scenario

When I Click On Button "X"

Given I See  Button "Y"

Then Button "Y" Is Visible

Given I See Button "Z"

When I Click On Button "Y"

The first thing it would do is the Givens, your prerequisites, in the order they are typed in the Scenario

Given I See Button "Y"

Given I See Button "Z"

It would do the Whens

When I Click On Button "X"

When I Click On Button "Y"

Finally, as expected, it would do the Then's

Then Button "Y" Is Visible.

So it is very probable, this scenario would fail, if you see button Y but only after Clicking On Button X?  As the Given that you should see Button Y is going to be the first thing run!

So group your Givens,  Whens and Thens and break them into different scenarios.   

When I Click On Button "X"

Then Button "Y" Is Visible

Given I See Button "Y"

Given I See Button "Z"

When I Click On Button "Y"

You should see it is now very different.   First, its cleaner,  a couple/three lines is easier to read, but also you can see the steps taken.   But if you look at that first scenario, we don't know if Button "Y" is visible, before clicking on Button "X"?  All we can test is that it is visible after we have clicked on Button "X",  maybe it has nothing to do with Button "X"?

By breaking it up, we can see how we can help it.  Maybe the real test is

Given I Do Not See Button "Y"

When I Click On Button "X"

Then Button "Y" Is Visible.

This looks like a perfect simple scenario!  Testing that button Y is only visible after I clicked on Button X.

There is the academic BDD that says every scenario should be a stand alone test, all the prerequisites are built in the Given, and a scenario should only be different actions and results.  In the world of databases that isn't possible,  running Test 1 may affect Test 2!  When we get to automation we can show how this works, but for manual BDD (or just BDD!) you read your scenarios like a book, from the top down, grouping your sentences by their keywords.  

©2020 by Agile Testing.