SlideShare une entreprise Scribd logo
1  sur  56
Télécharger pour lire hors ligne
Writing better
BDD scenarios
Bright Night
22nd March 2018
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
“The BDD Books: Discovery” • http://bddbooks.com
@gasparnagy • gaspar@specsolutions.eu
Copyright © Gaspar NagyCopyright © Gaspar Nagy
bdd addict
given.when.then
CAUTION!
on the stage
Gáspár Nagy
coach, trainer and bdd addict
creator of SpecFlow
gaspar@specsolutions.eu
https://specsolutions.eu
@gasparnagy
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Check out our new book!
• A BDD book for everyone (PO, BA, dev,
tester)
• Practical guide
• Demonstrates good collaboration
techniques, illustrated by concrete
examples
Find it on Leanpub through
http://bddbooks.com!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Agenda
• Short introduction to BDD
• What makes a scenario good?
• Identify and fix common problems
• Wrap-up: Checklist for good scenarios
Copyright © Gaspar NagyCopyright © Gaspar Nagy
What is BDD?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
[HttpPost]
public ActionResult Answer(int answer)
{
TriviaEntities db = new TriviaEntities();
var question = db.FindQuestion(CurrentQuestion);
if (question.Type == QuestionType.Easy)
{
db.AddScore(question, user, 10);
}
else
{
db.AddScore(question, user, 50);
}
var model = new GameModel
{ Score = db.GetScore(question, user) };
return View(model);
}
implement
feedback
Agile mini-waterfall
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Examples link requirements to software
Discovery
Automation with
Cucumber/SpecFlow
Copyright © Gaspar NagyCopyright © Gaspar Nagy
This is an example!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
This is an example formulated as a scenario!
Scenario: Correct easy answer scores 10
Given I register a team
When I submit a correct easy answer
Then my score should be 10
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Behavior Driven Development is about
understanding & validating
business requirements
through illustrative examples
Copyright © Gaspar NagyCopyright © Gaspar Nagy
BDD practices
Discovery
Shared understanding is established through
collaboration and structured conversations
Formulation
Examples of system behaviour are documented
as scenarios
Automation
Scenarios are automated to be able to verify the
system behaviour
Copyright © Gaspar NagyCopyright © Gaspar Nagy
What makes a scenario good?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Concrete
Declarative
Copyright © Gaspar NagyCopyright © Gaspar Nagy
What makes a scenario BAD?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Abadscenario
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box
'//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I hope you are still awake
And I clear text box '(//input[@type="text"])[2]’
And I type 'Gherkin, BDD, dontdothisplease' into the text box
'(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Averybadscenario
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box '//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I clear text box '(//input[@type="text"])[2]'
And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
And wait until link 'Test Question 123' becomes visible
And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is
'asked March 22, 2018 by John Doe'
When I scroll to element 'a[text()="Test Question 123"]/ancestor::li'
And I click on link 'Test Question 123'
And wait for 1500 ms
And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123'
And the text of element 'p' is 'With some details'
And I click on link 'Home'
Then browser title is 'SpecOverflow - Home'
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Averybadscenario
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box '//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I clear text box '(//input[@type="text"])[2]'
And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
And wait until link 'Test Question 123' becomes visible
And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is
'asked March 22, 2018 by John Doe'
When I scroll to element 'a[text()="Test Question 123"]/ancestor::li'
And I click on link 'Test Question 123'
And wait for 1500 ms
And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123'
And the text of element 'p' is 'With some details'
And I click on link 'Home'
Then browser title is 'SpecOverflow - Home'
Unclear
purpose
Testing
multiple
things
Wrong
language
Solution
details
(brittle)
Unnecessary
(confusing)
detailsDuplications
Hard to get
feedback
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Averybadscenario
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box '//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I clear text box '(//input[@type="text"])[2]'
And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
And wait until link 'Test Question 123' becomes visible
And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is
'asked March 22, 2018 by John Doe'
When I scroll to element 'a[text()="Test Question 123"]/ancestor::li'
And I click on link 'Test Question 123'
And wait for 1500 ms
And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123'
And the text of element 'p' is 'With some details'
And I click on link 'Home'
Then browser title is 'SpecOverflow - Home'
Unclear
purpose
Testing
multiple
things
Wrong
language
Solution
details
(brittle)
Unnecessary
(confusing)
detailsDuplications
Hard to get
feedback
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Thisscenarioisdescribed
usingbrowsercommands
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box '//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I clear text box '(//input[@type="text"])[2]'
And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
And wait until link 'Test Question 123' becomes visible
And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is
'asked March 22, 2018 by John Doe'
When I scroll to element 'a[text()="Test Question 123"]/ancestor::li'
And I click on link 'Test Question 123'
And wait for 1500 ms
And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123'
And the text of element 'p' is 'With some details'
And I click on link 'Home'
Then browser title is 'SpecOverflow - Home'
Copyright © Gaspar NagyCopyright © Gaspar Nagy
We want to document the requirements with
scenarios and get feedback about them from business.
They will not (be able to) give feedback about
scenarios using a technical language.
(Even if they understand click and fill…)
Source: http://knowyourmeme.com/memes/its-a-trap
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Findthebusiness
language!
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box
'//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I clear text box '(//input[@type="text"])[2]'
And I type 'Gherkin, BDD, dontdothisplease' into the text box
'(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
And wait until link 'Test Question 123' becomes visible
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenariorefactoredto
usebusinesslanguage
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the home page should be activated
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
When I navigate back to the home page
Then the home page should be activated
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Ubiquitous language – a language that
everyone (in the team) understands
Problem Domain Solution Domain
Form & Elm
• Navigate to URL
• Enter text
• Click
• Business works on “problem domain”
• Dev team works on the “solution domain”
Question
• Ask
• Answer Message
• Send
• Forward
CreateCustomer()
Question
• Ask
• Vote
• Answer
Tweet
• Tweet
• Retweet
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenariorefactoredto
usebusinesslanguage
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the home page should be activated
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| New question | This is what i need |
When I navigate back to the home page
Then the home page should be activated
Unclear
purpose
Testing
multiple
things
Wrong
language
Solution
details
(brittle)
Solution
details
(brittle)
Unnecessary
(confusing)
detailsDuplications
Hard to get
feedback
Duplications
Hard to get
feedback
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenariorefactoredto
usebusinesslanguage
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the home page should be activated
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| New question | This is what i need |
When I navigate back to the home page
Then the home page should be activated
Unclear
purpose
Testing
multiple
things
Wrong
language
Solution
details
(brittle)
Unnecessary
(confusing)
detailsDuplications
Hard to get
feedback
Testing
multiple
things
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Identifybusinessrules
verified!
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the home page should be activated
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
When I navigate back to the home page
Then the home page should be activated
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Multi-rule, multi-purpose scenarios causing
bottleneck in the development process.
Small, focused scenarios are much better!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Multi-purpose scenarios
• Big chunk of work – hard to see progress
• Chains business rules to each-other – causes unwanted dependencies
• Address multiple business rules – decrease possibilities, to split, parallelize or
defer work
• Might address different components of the system, developed by different
people/teams – the scenario becomes a no-one’s-child, or supervised by a
separated testing team/group (but we want to integrate them!)
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Identifybusinessrules
verified!
Scenario: Question Test
When I check the home page
Then the title should be 'SpecOverflow - Home’
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the home page should be activated
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| New question | 0 | 0 |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| New question | This is what i need |
When I navigate back to the home page
Then the home page should be activated
Why?
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
Scenario: New questions should be added to the question list
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Scenario: The details of the question can be accessed from the question list
Given I am logged in
And I have added a question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Focused? Better, but there are
duplications still…
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
Scenario: New questions should be added to the question list
Given I am logged in
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Scenario: The details of the question can be accessed from the question list
Given I am logged in
And I have added a question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
Multiplescenariostest
thesamething…
from
“What to do”
(imperative)
to
“What to expect”
(declarative)
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
@login
Scenario: New questions should be added to the question list
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
@login
Scenario: The details of the question can be accessed from the question list
Given there is a question added with
| Title | Body |
| Test Question 123 | With some details |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
Focused,declarative
scenarios
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
@login
Scenario: New questions should be added to the question list
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
@login
Scenario: The details of the question can be accessed from the question list
Given there is a question added with
| Title | Body |
| New question | This is what i need |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
Betterscenarios Unclear
purpose
Wrong
language
Solution
details
(brittle)
Unnecessary
(confusing)
detailsDuplicationsDuplications
Hard to get
feedback
Unclear
purpose
Testing
multiple
things
Hard to get
feedback
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
@login
Scenario: New questions should be added to the question list
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
@login
Scenario: The details of the question can be accessed from the question list
Given there is a question added with
| Title | Body |
| New question | This is what i need |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| Test Question 123 | With some details |
Betterscenarios Unclear
purpose
Wrong
language
Solution
details
(brittle)
Unnecessary
(confusing)
detailsDuplications
Hard to get
feedback
Testing
multiple
things
Unnecessary
(confusing)
details
Copyright © Gaspar NagyCopyright © Gaspar Nagy
@login
Scenario: New questions should be added to the question list
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Unnecessarydetails
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: Generate report for closed projects with total time
Given the following projects in the database
| PRJ_CODE | PRJ_TYPE | PRJ_STATUS |
| S2011LXS | I | C |
And the following time bookings in the database
| PRJ_CODE | NORMAL_TIME |
| S2011LXS | 9.0 |
| S2011LXS | 8.0 |
When the report generator is executed
Then the following report should be generated
| PRJ_CODE | TYPE | TIME |
| S2011LXS | C | 17.0 |
Confusingdetails
Why is it important
that the type is “I”?
Or is it just some
default value?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
More details does not necessarily mean more clarity.
Unnecessary, unimportant, irrelevant, incidental
details might cause confusion.
(And also bad for maintainability.)
Copyright © Gaspar NagyCopyright © Gaspar Nagy
@login
Scenario: New questions should be added to the question list
When I ask a new question with
| Title | Body | Tags |
| Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Keepessentialdetails!
Copyright © Gaspar NagyCopyright © Gaspar Nagy
@login
Scenario: New questions should be added to the question list
When I ask a new question with
| Title |
| Test Question 123 |
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Incidentaldetails
removed
Copyright © Gaspar NagyCopyright © Gaspar Nagy
@login
Scenario: New questions should be added to the question list
When I ask a new question 'Test Question 123'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Incidentaldetails
removed
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Is 'Test Question 123’
essential or incidental?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
@login
Scenario: New questions should be added to the question list
When I ask a new question 'Test Question 123'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Incidentaldetails
removed
@login
Scenario: New questions should be added to the question list
When I ask a new question
Then the question should appear in the question list with the specified title
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Sometimes a concrete piece of data can better
illustrate the story that we want to explain…
There is always a room for phrasing the things a bit
more abstract or more concrete…
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Is 'Test Question 123’
interesting?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
@login
Scenario: New questions should be added to the question list
When I ask a new question 'Test Question 123'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| Test Question 123 | 0 | 0 |
Realisticdatamakesthe
scenariosmoreconcrete
@login
Scenario: New questions should be added to the question list
When I ask a new question 'How to write better BDD scenarios?'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| How to write better BDD scenarios? | 0 | 0 |
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
@login
Scenario: New questions should be added to the question list
When I ask a new question 'How to write better BDD scenarios?'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| How to write better BDD scenarios? | 0 | 0 |
@login
Scenario: The details of the question can be accessed from the question list
Given there is a question added with
| Title | Body |
| How to write better BDD scenarios? | I can’t get it |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| How to write better BDD scenarios? | I can’t get it |
BetterBDDscenarios?
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
@login
Scenario: New questions should be added to the question list
When I ask a new question 'How to write better BDD scenarios?'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| How to write better BDD scenarios? | 0 | 0 |
@login
Scenario: The details of the question can be accessed from the question list
Given there is a question added with
| Title | Body |
| How to write better BDD scenarios? | I can’t get it |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| How to write better BDD scenarios? | I can’t get it |
BetterBDDscenarios? Unclear
purpose
Wrong
language
Solution
details
(brittle)
Duplications
Hard to get
feedback
Testing
multiple
things
Unnecessary
(confusing)
details
Hard to get
feedback
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Summary
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Fromaverybad
scenario
Scenario: Question Test
Given I navigate to 'http://specoverflow.com/#/'
And wait until link 'Home' becomes visible
Then browser title is 'SpecOverflow - Home'
Given I click on link 'Login'
And wait for 2000 ms
When I click on link 'Ask a question'
And wait for 500 ms
And I clear text box '//input[@type="text"]'
And I type 'Test Question 123' into the text box '//input[@type="text"]'
And I click on element '.ta-text .ta-bind'
And I type 'With some details' into the element '.ta-text .ta-bind'
And I clear text box '(//input[@type="text"])[2]'
And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]'
And I click on button '//div[4]/div/div'
And wait for 2000 ms
Then browser title is 'SpecOverflow - Home'
And wait for 1500 ms
And wait until link 'Test Question 123' becomes visible
And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is
'asked March 22, 2018 by John Doe'
When I scroll to element 'a[text()="Test Question 123"]/ancestor::li'
And I click on link 'Test Question 123'
And wait for 1500 ms
And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123'
And the text of element 'p' is 'With some details'
And I click on link 'Home'
Then browser title is 'SpecOverflow - Home'
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Scenario: The application home page is identifiable
When I check the home page
Then the title should be 'SpecOverflow - Home'
@login
Scenario: New questions should be added to the question list
When I ask a new question 'How to write better BDD scenarios?'
Then the question should appear in the question list with todays date as
| Title | Views | Votes |
| How to write better BDD scenarios? | 0 | 0 |
@login
Scenario: The details of the question can be accessed from the question list
Given there is a question added with
| Title | Body |
| How to write better BDD scenarios? | I can’t get it |
When I navigate to the question details from the home page
Then the question details should be visible
| Title | Body |
| How to write better BDD scenarios? | I can’t get it |
Tosomethingbetter
useful…
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Checklist for good scenarios
• Concrete — use actual data values in your examples.
• Essential — any data you use in an example should contribute to understanding
the behavior being illustrated.
• Focused — don't try to illustrate more than one interaction in any example.
• Interesting — every example should have a reason for existing. Try and give each
one an intention revealing name.
• Declarative — examples that declare what the user is trying to achieve are easier
to understand and maintain than those that describe imperatively what the user
does.
• Ubiquitous — avoid using terms that are understood by some of the team
members only. In general, try to use business terminology throughout.
Source: Seb Rose
Copyright © Gaspar NagyCopyright © Gaspar Nagy
Happy formulation!
Thank you!
Gáspár Nagy
coach • trainer • bdd addict • creator of specflow
“The BDD Books: Discovery” • http://bddbooks.com
@gasparnagy • gaspar@specsolutions.eu
Copyright © Gaspar NagyCopyright © Gaspar Nagy

Contenu connexe

Plus de Gáspár Nagy

Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Gáspár Nagy
 

Plus de Gáspár Nagy (12)

Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
Testing is Difficult (Agile in the City Bristol 2017, Lightening talk)
 
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (Qualit...
 
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
A tesztelés szerepe folyamatos kihelyezést használó projektekben (Microsoft, ...
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
 
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
Property Based BDD Examples (ETSI UCAAT 2016, Budapest)
 
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2...
 
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
Given/When/Then-ready sprint planning with Example Mapping (Agilia Budapest 2...
 
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (BDD Lond...
 
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Confere...
 
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
Folyamatos integráció és kódépítés (ALM Day Budapest, 24/11/2015, Hungarian)
 
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
Given/When/Then-ready sprint planning (Agile Tour Vienna 2015)
 

Dernier

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Dernier (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 

Writing better BDD scenarios (Bright Night hosted by Brightest, Kontich 2018)

  • 1. Writing better BDD scenarios Bright Night 22nd March 2018 Gáspár Nagy coach • trainer • bdd addict • creator of specflow “The BDD Books: Discovery” • http://bddbooks.com @gasparnagy • gaspar@specsolutions.eu
  • 2. Copyright © Gaspar NagyCopyright © Gaspar Nagy bdd addict given.when.then CAUTION! on the stage Gáspár Nagy coach, trainer and bdd addict creator of SpecFlow gaspar@specsolutions.eu https://specsolutions.eu @gasparnagy
  • 3. Copyright © Gaspar NagyCopyright © Gaspar Nagy Check out our new book! • A BDD book for everyone (PO, BA, dev, tester) • Practical guide • Demonstrates good collaboration techniques, illustrated by concrete examples Find it on Leanpub through http://bddbooks.com!
  • 4. Copyright © Gaspar NagyCopyright © Gaspar Nagy Agenda • Short introduction to BDD • What makes a scenario good? • Identify and fix common problems • Wrap-up: Checklist for good scenarios
  • 5. Copyright © Gaspar NagyCopyright © Gaspar Nagy What is BDD?
  • 6. Copyright © Gaspar NagyCopyright © Gaspar Nagy [HttpPost] public ActionResult Answer(int answer) { TriviaEntities db = new TriviaEntities(); var question = db.FindQuestion(CurrentQuestion); if (question.Type == QuestionType.Easy) { db.AddScore(question, user, 10); } else { db.AddScore(question, user, 50); } var model = new GameModel { Score = db.GetScore(question, user) }; return View(model); } implement feedback Agile mini-waterfall
  • 7. Copyright © Gaspar NagyCopyright © Gaspar Nagy Examples link requirements to software Discovery Automation with Cucumber/SpecFlow
  • 8. Copyright © Gaspar NagyCopyright © Gaspar Nagy This is an example!
  • 9. Copyright © Gaspar NagyCopyright © Gaspar Nagy This is an example formulated as a scenario! Scenario: Correct easy answer scores 10 Given I register a team When I submit a correct easy answer Then my score should be 10
  • 10. Copyright © Gaspar NagyCopyright © Gaspar Nagy Behavior Driven Development is about understanding & validating business requirements through illustrative examples
  • 11. Copyright © Gaspar NagyCopyright © Gaspar Nagy BDD practices Discovery Shared understanding is established through collaboration and structured conversations Formulation Examples of system behaviour are documented as scenarios Automation Scenarios are automated to be able to verify the system behaviour
  • 12. Copyright © Gaspar NagyCopyright © Gaspar Nagy What makes a scenario good?
  • 13. Copyright © Gaspar NagyCopyright © Gaspar Nagy Concrete Declarative
  • 14. Copyright © Gaspar NagyCopyright © Gaspar Nagy What makes a scenario BAD?
  • 15. Copyright © Gaspar NagyCopyright © Gaspar Nagy Abadscenario Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I hope you are still awake And I clear text box '(//input[@type="text"])[2]’ And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms
  • 16. Copyright © Gaspar NagyCopyright © Gaspar Nagy Averybadscenario Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I clear text box '(//input[@type="text"])[2]' And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms And wait until link 'Test Question 123' becomes visible And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is 'asked March 22, 2018 by John Doe' When I scroll to element 'a[text()="Test Question 123"]/ancestor::li' And I click on link 'Test Question 123' And wait for 1500 ms And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123' And the text of element 'p' is 'With some details' And I click on link 'Home' Then browser title is 'SpecOverflow - Home'
  • 17. Copyright © Gaspar NagyCopyright © Gaspar Nagy
  • 18. Copyright © Gaspar NagyCopyright © Gaspar Nagy Averybadscenario Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I clear text box '(//input[@type="text"])[2]' And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms And wait until link 'Test Question 123' becomes visible And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is 'asked March 22, 2018 by John Doe' When I scroll to element 'a[text()="Test Question 123"]/ancestor::li' And I click on link 'Test Question 123' And wait for 1500 ms And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123' And the text of element 'p' is 'With some details' And I click on link 'Home' Then browser title is 'SpecOverflow - Home' Unclear purpose Testing multiple things Wrong language Solution details (brittle) Unnecessary (confusing) detailsDuplications Hard to get feedback
  • 19. Copyright © Gaspar NagyCopyright © Gaspar Nagy Averybadscenario Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I clear text box '(//input[@type="text"])[2]' And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms And wait until link 'Test Question 123' becomes visible And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is 'asked March 22, 2018 by John Doe' When I scroll to element 'a[text()="Test Question 123"]/ancestor::li' And I click on link 'Test Question 123' And wait for 1500 ms And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123' And the text of element 'p' is 'With some details' And I click on link 'Home' Then browser title is 'SpecOverflow - Home' Unclear purpose Testing multiple things Wrong language Solution details (brittle) Unnecessary (confusing) detailsDuplications Hard to get feedback
  • 20. Copyright © Gaspar NagyCopyright © Gaspar Nagy Thisscenarioisdescribed usingbrowsercommands Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I clear text box '(//input[@type="text"])[2]' And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms And wait until link 'Test Question 123' becomes visible And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is 'asked March 22, 2018 by John Doe' When I scroll to element 'a[text()="Test Question 123"]/ancestor::li' And I click on link 'Test Question 123' And wait for 1500 ms And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123' And the text of element 'p' is 'With some details' And I click on link 'Home' Then browser title is 'SpecOverflow - Home'
  • 21. Copyright © Gaspar NagyCopyright © Gaspar Nagy We want to document the requirements with scenarios and get feedback about them from business. They will not (be able to) give feedback about scenarios using a technical language. (Even if they understand click and fill…)
  • 23. Copyright © Gaspar NagyCopyright © Gaspar Nagy Findthebusiness language! Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I clear text box '(//input[@type="text"])[2]' And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms And wait until link 'Test Question 123' becomes visible Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease |
  • 24. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenariorefactoredto usebusinesslanguage Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the home page should be activated Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details | When I navigate back to the home page Then the home page should be activated
  • 25. Copyright © Gaspar NagyCopyright © Gaspar Nagy Ubiquitous language – a language that everyone (in the team) understands Problem Domain Solution Domain Form & Elm • Navigate to URL • Enter text • Click • Business works on “problem domain” • Dev team works on the “solution domain” Question • Ask • Answer Message • Send • Forward CreateCustomer() Question • Ask • Vote • Answer Tweet • Tweet • Retweet
  • 26. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenariorefactoredto usebusinesslanguage Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the home page should be activated Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | New question | This is what i need | When I navigate back to the home page Then the home page should be activated Unclear purpose Testing multiple things Wrong language Solution details (brittle) Solution details (brittle) Unnecessary (confusing) detailsDuplications Hard to get feedback Duplications Hard to get feedback
  • 27. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenariorefactoredto usebusinesslanguage Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the home page should be activated Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | New question | This is what i need | When I navigate back to the home page Then the home page should be activated Unclear purpose Testing multiple things Wrong language Solution details (brittle) Unnecessary (confusing) detailsDuplications Hard to get feedback Testing multiple things
  • 28. Copyright © Gaspar NagyCopyright © Gaspar Nagy Identifybusinessrules verified! Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the home page should be activated Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details | When I navigate back to the home page Then the home page should be activated
  • 29. Copyright © Gaspar NagyCopyright © Gaspar Nagy Multi-rule, multi-purpose scenarios causing bottleneck in the development process. Small, focused scenarios are much better!
  • 30. Copyright © Gaspar NagyCopyright © Gaspar Nagy Multi-purpose scenarios • Big chunk of work – hard to see progress • Chains business rules to each-other – causes unwanted dependencies • Address multiple business rules – decrease possibilities, to split, parallelize or defer work • Might address different components of the system, developed by different people/teams – the scenario becomes a no-one’s-child, or supervised by a separated testing team/group (but we want to integrate them!)
  • 31. Copyright © Gaspar NagyCopyright © Gaspar Nagy Identifybusinessrules verified! Scenario: Question Test When I check the home page Then the title should be 'SpecOverflow - Home’ Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the home page should be activated Then the question should appear in the question list with todays date as | Title | Views | Votes | | New question | 0 | 0 | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | New question | This is what i need | When I navigate back to the home page Then the home page should be activated Why? Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' Scenario: New questions should be added to the question list Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Scenario: The details of the question can be accessed from the question list Given I am logged in And I have added a question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details |
  • 32. Copyright © Gaspar NagyCopyright © Gaspar Nagy Focused? Better, but there are duplications still…
  • 33. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' Scenario: New questions should be added to the question list Given I am logged in When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Scenario: The details of the question can be accessed from the question list Given I am logged in And I have added a question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details | Multiplescenariostest thesamething… from “What to do” (imperative) to “What to expect” (declarative)
  • 34. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' @login Scenario: New questions should be added to the question list When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | @login Scenario: The details of the question can be accessed from the question list Given there is a question added with | Title | Body | | Test Question 123 | With some details | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details | Focused,declarative scenarios
  • 35. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' @login Scenario: New questions should be added to the question list When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | @login Scenario: The details of the question can be accessed from the question list Given there is a question added with | Title | Body | | New question | This is what i need | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details | Betterscenarios Unclear purpose Wrong language Solution details (brittle) Unnecessary (confusing) detailsDuplicationsDuplications Hard to get feedback Unclear purpose Testing multiple things Hard to get feedback
  • 36. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' @login Scenario: New questions should be added to the question list When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | @login Scenario: The details of the question can be accessed from the question list Given there is a question added with | Title | Body | | New question | This is what i need | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | Test Question 123 | With some details | Betterscenarios Unclear purpose Wrong language Solution details (brittle) Unnecessary (confusing) detailsDuplications Hard to get feedback Testing multiple things Unnecessary (confusing) details
  • 37. Copyright © Gaspar NagyCopyright © Gaspar Nagy @login Scenario: New questions should be added to the question list When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Unnecessarydetails
  • 38. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: Generate report for closed projects with total time Given the following projects in the database | PRJ_CODE | PRJ_TYPE | PRJ_STATUS | | S2011LXS | I | C | And the following time bookings in the database | PRJ_CODE | NORMAL_TIME | | S2011LXS | 9.0 | | S2011LXS | 8.0 | When the report generator is executed Then the following report should be generated | PRJ_CODE | TYPE | TIME | | S2011LXS | C | 17.0 | Confusingdetails Why is it important that the type is “I”? Or is it just some default value?
  • 39. Copyright © Gaspar NagyCopyright © Gaspar Nagy More details does not necessarily mean more clarity. Unnecessary, unimportant, irrelevant, incidental details might cause confusion. (And also bad for maintainability.)
  • 40. Copyright © Gaspar NagyCopyright © Gaspar Nagy @login Scenario: New questions should be added to the question list When I ask a new question with | Title | Body | Tags | | Test Question 123 | With some details | Gherkin, BDD, dontdothisplease | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Keepessentialdetails!
  • 41. Copyright © Gaspar NagyCopyright © Gaspar Nagy @login Scenario: New questions should be added to the question list When I ask a new question with | Title | | Test Question 123 | Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Incidentaldetails removed
  • 42. Copyright © Gaspar NagyCopyright © Gaspar Nagy @login Scenario: New questions should be added to the question list When I ask a new question 'Test Question 123' Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Incidentaldetails removed
  • 43. Copyright © Gaspar NagyCopyright © Gaspar Nagy Is 'Test Question 123’ essential or incidental?
  • 44. Copyright © Gaspar NagyCopyright © Gaspar Nagy @login Scenario: New questions should be added to the question list When I ask a new question 'Test Question 123' Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Incidentaldetails removed @login Scenario: New questions should be added to the question list When I ask a new question Then the question should appear in the question list with the specified title
  • 45. Copyright © Gaspar NagyCopyright © Gaspar Nagy Sometimes a concrete piece of data can better illustrate the story that we want to explain… There is always a room for phrasing the things a bit more abstract or more concrete…
  • 46. Copyright © Gaspar NagyCopyright © Gaspar Nagy Is 'Test Question 123’ interesting?
  • 47. Copyright © Gaspar NagyCopyright © Gaspar Nagy @login Scenario: New questions should be added to the question list When I ask a new question 'Test Question 123' Then the question should appear in the question list with todays date as | Title | Views | Votes | | Test Question 123 | 0 | 0 | Realisticdatamakesthe scenariosmoreconcrete @login Scenario: New questions should be added to the question list When I ask a new question 'How to write better BDD scenarios?' Then the question should appear in the question list with todays date as | Title | Views | Votes | | How to write better BDD scenarios? | 0 | 0 |
  • 48. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' @login Scenario: New questions should be added to the question list When I ask a new question 'How to write better BDD scenarios?' Then the question should appear in the question list with todays date as | Title | Views | Votes | | How to write better BDD scenarios? | 0 | 0 | @login Scenario: The details of the question can be accessed from the question list Given there is a question added with | Title | Body | | How to write better BDD scenarios? | I can’t get it | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | How to write better BDD scenarios? | I can’t get it | BetterBDDscenarios?
  • 49. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' @login Scenario: New questions should be added to the question list When I ask a new question 'How to write better BDD scenarios?' Then the question should appear in the question list with todays date as | Title | Views | Votes | | How to write better BDD scenarios? | 0 | 0 | @login Scenario: The details of the question can be accessed from the question list Given there is a question added with | Title | Body | | How to write better BDD scenarios? | I can’t get it | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | How to write better BDD scenarios? | I can’t get it | BetterBDDscenarios? Unclear purpose Wrong language Solution details (brittle) Duplications Hard to get feedback Testing multiple things Unnecessary (confusing) details Hard to get feedback
  • 50. Copyright © Gaspar NagyCopyright © Gaspar Nagy Summary
  • 51. Copyright © Gaspar NagyCopyright © Gaspar Nagy Fromaverybad scenario Scenario: Question Test Given I navigate to 'http://specoverflow.com/#/' And wait until link 'Home' becomes visible Then browser title is 'SpecOverflow - Home' Given I click on link 'Login' And wait for 2000 ms When I click on link 'Ask a question' And wait for 500 ms And I clear text box '//input[@type="text"]' And I type 'Test Question 123' into the text box '//input[@type="text"]' And I click on element '.ta-text .ta-bind' And I type 'With some details' into the element '.ta-text .ta-bind' And I clear text box '(//input[@type="text"])[2]' And I type 'Gherkin, BDD, dontdothisplease' into the text box '(//input[@type="text"])[2]' And I click on button '//div[4]/div/div' And wait for 2000 ms Then browser title is 'SpecOverflow - Home' And wait for 1500 ms And wait until link 'Test Question 123' becomes visible And the text of element 'a[text()="Test Question 123"]/ancestor::li/div/div[2]/div[2]/div[2]' is 'asked March 22, 2018 by John Doe' When I scroll to element 'a[text()="Test Question 123"]/ancestor::li' And I click on link 'Test Question 123' And wait for 1500 ms And the text of element 'h1.answer-title.ng-binding' is 'Test Question 123' And the text of element 'p' is 'With some details' And I click on link 'Home' Then browser title is 'SpecOverflow - Home'
  • 52. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: The application home page is identifiable When I check the home page Then the title should be 'SpecOverflow - Home' @login Scenario: New questions should be added to the question list When I ask a new question 'How to write better BDD scenarios?' Then the question should appear in the question list with todays date as | Title | Views | Votes | | How to write better BDD scenarios? | 0 | 0 | @login Scenario: The details of the question can be accessed from the question list Given there is a question added with | Title | Body | | How to write better BDD scenarios? | I can’t get it | When I navigate to the question details from the home page Then the question details should be visible | Title | Body | | How to write better BDD scenarios? | I can’t get it | Tosomethingbetter useful…
  • 53. Copyright © Gaspar NagyCopyright © Gaspar Nagy Checklist for good scenarios • Concrete — use actual data values in your examples. • Essential — any data you use in an example should contribute to understanding the behavior being illustrated. • Focused — don't try to illustrate more than one interaction in any example. • Interesting — every example should have a reason for existing. Try and give each one an intention revealing name. • Declarative — examples that declare what the user is trying to achieve are easier to understand and maintain than those that describe imperatively what the user does. • Ubiquitous — avoid using terms that are understood by some of the team members only. In general, try to use business terminology throughout. Source: Seb Rose
  • 54. Copyright © Gaspar NagyCopyright © Gaspar Nagy Happy formulation!
  • 55. Thank you! Gáspár Nagy coach • trainer • bdd addict • creator of specflow “The BDD Books: Discovery” • http://bddbooks.com @gasparnagy • gaspar@specsolutions.eu
  • 56. Copyright © Gaspar NagyCopyright © Gaspar Nagy