Then When Given

Kishen Steve Simbhoedatpanday
2 min readOct 17, 2014

People who practice BDD and/or ATDD all know how frustrating it can be to write automated examples. Especially when you get stuck overthinking the preconditions of examples.

Then When Given Map

This post describes an alternative approach to writing acceptance tests: write them backwards!

Imagine that you are building the very first online phone book. We need to define an acceptance tests for viewing the location of a florist. Using the Given-When-Then formula you would probably describe the behaviour like this.

Given I am on the online phone book homepage
When I type "Florist" in the business type field
And I click ...
...

Most of the time you will be discussing and describing details that have nothing to do with viewing the location of a florist. To avoid this, write down the Then clause of the formula first.
Make sure the Then clause contains an observable result.

Then I see the location "Floriststreet 123"

Next, we will try to answer the following question: What caused the Then clause?
Make sure the When clause contains an actor and an action.

When I click "View map" of the search result
Then I see the location "Floriststreet 123"

The last thing we will need to do is answer the following question: Why can I perform that action?
Make sure the Given clause contains a simple precondition.

Given I see a search result for florist "Floral Designs"
When I click "View map" of the search result
Then I see the location "Floriststreet 123"

You might have noticed that I left out certain parts where the user goes to the homepage and selects UI objects in the search area. It was not worth mentioning in the Given-When-Then formula. Too much details make us lose focus of what we really want to check. The essence of this acceptance test is clicking on the link “View map” and exposing the location to the user.

Try it a couple of times and let me know how it went.

--

--

Kishen Steve Simbhoedatpanday

Software Test Developer. Podcast host @codeklets. Living room DJ. Married to @jufsantweet & father of Jayden & Mila.