Switching from Arrange-Act-Assert (AAA) to Given-When-Then (GWT)
 has been a game-changer for me. I’m so convinced of its benefits that I say No GWT, No Code!

Adopting the GWT approach is not an overnight process. It requires time, patience, and practice to become fluent in it, and like with any writing, it takes a lot of rewriting. But trust me, the effort is worth it.

In this post, I’ll share one way of thinking about it that helps me and has helped others. Hopefully, it’ll help you, too.

Framing Past, Present, and Future

GWTs describe one or more scenarios of a user story.

I frame each section as follows:

  • Given: Past
  • When: Present
  • Then: Future

An image like this forms in my mind:

Given I got to the ship (past)
When I travel on it (present)
Then I arrive at great destinations (future)

Dissecting each part:

  • The then part describes a story’s desired outcome in the future (years ahead or just a moment after the activity that happened in the present). Start with the end in mind.
  • The when part is usually associated with the main activity of the story. It is the present time when the main activity is happening.
  • The given part describes what has happened in the past (years ago or just a moment ago, it doesn’t matter) and is essential for what is happening in the present moment (when), to get to the desired future (then).

Putting it another way, I ask myself:

  • Then: What’s the desired outcome in the future?
  • When: What’s the event happening at the present moment?
  • Given: What conditions or factors need to be in place for the activity in the present to produce the desired future?

Let’s look at a couple of examples.

Applying for a Passport

Let’s pretend we have a story that describes the outcomes of applying for a passport:

In order to travel internationally for my individual growth
As a Traveller
I want to apply for a passport

The happy path scenario for this story is described as such:

Given I have a valid US birth certificate
  and a passport application form correctly filled out
When I file my application
Then I see a confirmation that my application is being processed
  and I am informed of how I can check for a status

I like turning those words into pictures in my mind:

A few things to note:

  • What makes a birth certificate valid? In this scenario, it may not matter. This kind of detail is described elsewhere.
  • If an adult is applying for a passport, the birth certificate was likely issued several years ago. When? Who issued it? Where? Those questions don’t matter here because…
  • We are given a “passport application form correctly filled out.” What makes it correct? That information is also described elsewhere (e.g., “It must be a US birth certificate,” “the date of birth on the application must match that on the birth certificate, etc.). It’s possible there would be a story describing the activity of “filling out a passport application form”

Checking in to an international flight

Let’s now consider a story about the outcome of a person checking in for an international flight at an airport:

In order to get on an international flight
As a Traveller
I want to have a boarding pass

The happy path scenario for this story is described as such:

Given I have a valid US passport
  and a proper tourist visa stamp to Brazil
  and a valid flight confirmation
When I check in at the airport
Then I receive a boarding pass

This is how I picture that scenario:

Other stories describe how to “apply for a visa and get a visa stamp” and “book a flight and get a flight confirmation.”

Other Resources

Some great books that provide thorough examples:

Check out Improving’s Acceptance and Test-Driven Development 3-day course for a deeper dive into these practices.

5 responses to “Given-When-Then: Past, Present, and Future”

  1. […] Given-When-Then: Past, Present, and Future […]

  2. […] Share your own story-writing guidelines (like “cinematic user stories” or Gherkin format) […]

  3. […] Here’s one of my experiments mixing techniques I learned in See What I Mean and UZMO: Given-When-Then: Past, Present, and Future. […]

  4. […] connects directly to how I frame Given-When-Then scenarios: Given is past, When is present, Then is future. The Given section describes what has already […]

Leave a Reply

Trending

Discover more from Claudio Lassala's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading