Stories and Features
Let us stick to our Greek Poems, if you don't get BDD at least you'll have had a classical education (I went to a school where Homer was home reading)!
Odysseus finally arrives home from fighting in the Trojan war. He dresses up as a beggar and finds out who has been loyal to him. Once he is sure of their loyalty he announces that he, Odysseus, their king, has returned. But they do not believe him, he has been away for such a long time!
Penelope, his wife asks if he wishes the bed to be moved. Only the real Odysseus knows the bed is made from a living tree and thus can not be moved!
We have a story...
Penelope will test the person claiming to be Odysseus to prove if they really are!
This is a high level story, we could call this a user story. We can even BDD this.
Given I Am Penelope
When I Test The Person Claiming To Be Odysseus
Then I Will Know If It Is Odysseus
Given, prerequisites, only Penelope is doing this test. When, action, she will be the person doing the test. Then she will have the result from the test.
But this is too high a level to build code for. The developer does not know how Penelope will test Odysseus? How will developer know what the correct answer is? And as we are not writing a book, we are writing an application, the developer has to also know what happens if the wrong answer is given!
We create a feature. We break the user story down into multiple scenarios:-
Given I Am Penelope
Given I Have Offered To Move The Bed
When The Other Person Disagrees
Then They Are Odysseus
Given I Am Penelope
Given I Have Offered To Move The Bed
When The Other Person Agrees
Then They Are Not Odysseus
The developer doesn't need to know that the bed is part of a living tree and can not be moved, all they have to develop is the two Thens, the handling of the results. They have to develop a way for the person being asked to Disagree or Accept. A Way to deliver the question and a way to know they are Penelope. These are the tasks - the things needed to complete the feature.
We do not test tasks, individually. These will be tested as part of the feature. But a developer can check each sentence to get a pass or a fail as they build the development.
Let us work through it:-
Given I Am Penelope
In an application this is most likely a login. I need a way to enter the application as this specific user. So I have logged in as Penelope (what happens if I'm not Penelope, we haven't covered this in the user story, so the question needs to be asked) - we are asking questions to the person writing the user stories and we haven't even opened the development tool. If I can not login as Penelope - then this feature will fail!
Given I Have Offered To Move The Bed
This is where we introduce story boards, some way of saying to the writer of the User Story, this is what I am going to show. I could have a drop down with multiple questions, a radio button, a free text field. I need a Scenario that ends "Given I Have Offered To Move The Bed". For now, lets assume I, as the Product Manager, am happy that there is a drop down, with a list of questions and one of those questions is this.
When The Other Person Disagrees
A little bit difficult here, as we do not have other people in an application. All we are saying here is that someone has said No. I have selected a question, and we have their answer. The answer is Disagree.
Then They Are Odysseus
Only Odysseus would know the bed can not be moved! He answered the question with a no, thus it is him!
When The Other Person Agrees
Of course a normal person would want the bed moved, but only Odysseus would know it can not be moved. The someone has chosen yes. They were asked the question, and their answer, of Agree
Then They Are Not Odysseus
No way Odysseus would ask for the bed to be moved, it would kill the living tree it is housed in. He answered with a yes, it is NOT him!
2 Scenarios, both having the same 2 prerequisites, but 2 different actions, resulting in 2 different outcomes!
The developer can look at the resulting Thens and ask further questions. What will happen to the person having now proved they are not Odysseus? What happens if it is Odysseus? Working with the Product Owner, they could come up with more scenarios.
Given They Are Odysseus
Then A Big Party Is Thrown
Given They Are Not Odysseus
Then They Are Killed
More?
Given They Are Killed
Then Application Closes
Given A Big Party Is Thrown
When Odysseus Starts The Conga Line
Then Everyone Joins In...
I know taking it too far!!!
We have taken a user story, and made it very simple, very clear. We have agreement to what it will look like, how it will work and NOW we can develop an agreed feature.
This may not be the last we hear of Odysseus, but I promise from now on it will be much more development.