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
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
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
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'
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…
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
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
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