Blog

Then When Given

17 Oct, 2014

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

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.

Qxperts. We empower companies to deliver reliable & high-quality software. Any questions? We are here to help! www.qxperts.io

guest
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Luuk
Luuk
7 years ago

excellent!

Sandeep Singh
Sandeep Singh
7 years ago

Quite an interesting take on the BDD/ATDD approach. Would be giving it a try & update on the result.

kelly
kelly
6 years ago

Interesting! Is there still the need of acceptance criteria? Or could you make of every criteria a new given, then, when formula?
For one given there might be multiple when and thens, the variables?

Jordann Gross
Jordann Gross
6 years ago

Nice Kishen, I use a comparable start-with-the-goal-in-mind method to make it easier to create user stories and make them feel less ‘forced’.
Normal user story format often proposed is:
* As a , I want to , so that .
More than preferred this drives people to focus on intended interaction and then treat the business goal as an afterthought. Or leave it out even, because nobody has time for that after a few sprints, right?
That’s why I tend to propose to reverse the order, just like you proposed in this blog:
* In order to , I want to , as a .
This makes one thoroughly think through their end goal. After that you think about the way to reach that and to whom it brings the greatest benefit. In my perception this sometimes also results in different roles than initially thought. Meaning that the intended actor didn’t turn out to be the best one after all and thus improving the quality of your stories.
The end. More quality is more better. Everybody happy! 🙂

Explore related posts