testing requirements with bdd
TRANSCRIPT
Testing Requirements with
BDD
Alan Parkinson@alan_parkinson
The Requirements Crisis
We like to solve
complex problems
Scope creep
Solution
Simple
Bug Tennis
Developers
Vs
Testers
The Requirements Crisis
50-60% of all defects are requirement
defects
A User Story is just a placeholder for a conversation
between the three amigos
Illusion of transparency
tendency for people to overestimate how well they understand others' personal mental states
Acceptance Criteria
Rules are difficult to communicate
People end up with a fuzzy understanding
Can you give me an example?
Upgrade Gold and Platinum Loyalty members to Superior Rooms if
available
BDD uses examples to illustrate behaviour
Demonstrates how acceptance criteria behaves in a particular situation from a
particular point of view
BDD uses examples to illustrate behaviour
Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen the user checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Examples raise questions….
How do we decide if a room is available?
What if a room is not available. Do they get a alternative reward?
Is superior a room type or just any room better than
a standard room?
Donald Rumsfeld, a BDD thinker
there are known knowns; there are things we know we know.
We also know there are known unknowns; that is to say we know there are some
things we do not know.
But there are also unknown unknowns ”
“
There is no such thing as a dumb question
“unknown knowns”
Information we know about but
are not willing to consider… often seen in “group think”
Deeper examples
Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen Roy the receptionist checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Use real people, roles or actorsGiven a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen Roy the receptionist checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen Roy the receptionist checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Actors vs Personas
Deeper examples
Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen Roy the receptionist checks in the guestAnd a superior room is availableThen the guest will be upgraded to the superior room
Inject Uncertainly with “should”Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen Roy the receptionist checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Which come first:Acceptance Criteria or Examples?
Neither!
Both can be used to discover the other
Ask the Product Owner: Can you give
me an example?
Iterator over the context to discover new Examples
Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen the user checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Given a guest with a standard room reservationAnd the guest is a gold loyalty memberAnd there are superior rooms availableWhen the user checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Given a guest with a king room reservationAnd the guest is a platinum loyalty memberAnd there are superior rooms availableWhen the user checks in the guestAnd a superior room is availableThen the guest should be upgraded to the superior room
Examples change our style of writing and
automating
Given a customer “alan” exists with password “secret”
And I am not logged in
When I navigate to the account page
Then I am redirected to the login form
When I enter the “username” with “alan”
And I enter the “password” with “secret”
And I press “login”
Then I am redirected to my account page
Given a customer “alan” exists with password “secret”
And I am on the login form
When I enter the “username” with “alan”
And I enter the “password” with “secret”
And I press “login”
...
...
Imperative style
Command driven, List of instructions, explicit steps on how
to do something
Given a customer “alan” exists with password “secret”
And I am not logged in
When I navigate to the account page
Then I am redirected to the login form
When I enter the “username” with “alan”
And I enter the “password” with “secret”
And I press “login”
Then I am redirected to my account page
What if we wanted to change our Authentication
Method?
We would have to change every mention of the login form
in our tests
That`s a pretty brittle piece of Automation
Largest cause of Story based Automation failures
Declarative style
Describes what to do but not how to do it
“How should it Behave?”
not
“How should I Test it?”
Given a customer “alan” exists with password “secret”
And I am not logged in
When I navigate to the account page
Then I am redirected to the login form
When I enter the “username” with “alan”
And I enter the “password” with “secret”
And I press “login”
Then I am redirected to my account page
Given I am an unauthenticated customer
When I attempt to view the account page
Then I am asked to authenticate
When I authenticate with valid customer
credentials
Then I am shown the account page
Test related details are pushed down into step
implementations
Simple to maintain… Only the step definition
needs to change
Given a customer “alan” exists with password “secret”
And I am not logged in
Given I am an unauthenticated customer
When I navigate to the account page
Then I am redirected to the login form
When I attempt to view the account page
Then I am asked to authenticate
When I enter the “username” with “alan”
And I enter the “password” with “secret”
And I press “login”
When I authenticate with valid customer
credentials
Questions
Testing Requirements with
BDD
Alan Parkinson
@alan_parkinson