SlideShare a Scribd company logo
Readability and Maintainability
Writing Good
Cucumber Well
Readability
Maintainability
Features/Scenarios
Step Definitions
Data Objects
Page Objects
TestFactory
Watir
Selenium
Ruby
● Feature
● Summary
● Scenario
Cucumber’s Parts
● Feature
● Summary
● Scenario
Cucumber’s Parts
“What is the point?”
“Why is this a feature?”
“Who is going to care?”
● We are all QA
● If it’s not readable no one will read it
● “Living” requirements documentation
● Ubiquitous language
Theme: Effective Communication
Why “Readable” Cucumber?
Write a scenario without thinking about...
● User Interface
● The needs of the Ruby code
Instead, pretend you’re talking to a SME
(Be okay with getting it wrong the first time, because you will)
The Basic Approach
Ask yourself this question:
“If the entire system were scrapped and re-written
from scratch, what is the likelihood that this
Feature/Scenario would survive in its present form?”
The Basic Approach
Unit Tests
● Fields allowing certain character sets
● Select lists containing expected values
● Document IDs unique
User Interface Tests
● Element alignments
● Usability considerations
Performance Tests
● Page loading
● Server calls
Cucumber is not suited for...
I create a proposal
Declarative versus Imperative
I go to the login page
I enter my user name
I enter my password
I click the login button
I click the “Create Proposal” link
I click the “expand all” button
I type “Title” in the title field
I select “New” in the Type selection list
I type “00340” in the Sponsor Code field
I type today’s date into the Start Date field
I type tomorrow’s date into the End Date field
I click on the save button
...
I create a proposal
Declarative In Detail
in the BL-BL unitwith a 5-year budgetwith a Federal sponsorwithout a PIstarting next yearhaving a sponsor deadline
Given a particular system
state
When a specific event
occurs
Then a new state is
expected
● Everything needed for the
test/requirement to be valid is
spelled out concisely
● Everything not needed is left
out
● The point is explicit
● The expected/desired outcome
is comprehensible
● Remember that the user has
some goal in mind--some
reason for using the software
Given/When/Then
Scenario: Create Proposal with Invalid Sponsor
Given a user exists with the role Proposal Creator
When the proposal creator creates a proposal with an invalid sponsor
Then an error should say that a valid sponsor is required
Scenario: Adding an F&A rate to an Award
Given a User exists with the role Award Modifier
And the Award Modifier creates an Award
When the Award Modifier adds an F&A rate to the Award
Then the default start and end dates are based on the F&A rate's fiscal year
Scenario: Protocol submitted to a Committee with submission date restrictions
Given users exist with the roles IRB Administrator and Protocol Creator
And the IRB Admin submits a committee with events scheduled before and after its adv
submission days setting
And the Protocol Creator creates an IRB Protocol in the committee's home unit
When the Protocol is being submitted to the committee for review
Then the earliest available schedule date is based on the committee's Adv Submission Days value
Examples - Scenario Title
Given I am logged in as "@PersonX@"
And I attempt to view the portal page
When I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to "@project_code.project-manager-principal@"
And I set Chart Code to "@project_code.chart-code@"
And I set Organization Code to "@project_code.org-code@"
And I submit the document
And I acknowledge the document as "@project_code.reviewer1@"
And I acknowledge the document as "@project_code.reviewer2@"
Then it should go to a Final Status
Example - Yikes!
Given I am logged in as "@PersonX@"
And I attempt to view the portal page
When I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to "@project_code.project-manager-principal@"
And I set Chart Code to "@project_code.chart-code@"
And I set Organization Code to "@project_code.org-code@"
And I submit the document
And I acknowledge the document as "@project_code.reviewer1@"
And I acknowledge the document as "@project_code.reviewer2@"
Then it should go to a Final Status
Example - Yikes!
Only “@PersonX@”???
Seems like this, and the other “@” lines are
sneaky bits of code, which is a no-no at the
Scenario level!
Given I am logged in as an Administrator
And I attempt to view the portal page
When I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
And I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
Given I am logged in as an Administrator
And I attempt to view the portal page
When I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
And I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
How do you code for an “attempt”?
Why is “viewing” the portal page
important for this scenario?
Given I am logged in as an Administrator
And I attempt to view the portal page
When I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
And I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
Given I am logged in as an Administrator
When I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
And I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
What is the pivotal, state-changing
event in this scenario?
Given I am logged in as an Administrator
And I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
Given I am logged in as an Administrator
And I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
Why isn’t every bit of data in the test
being remembered automatically?
Is it really important to explicitly state
this stuff in the scenario?
Also, these steps seem dangerously
vague. Will they always work?
Given I am logged in as an Administrator
And I access the Project Code maintenance document
And I fill in a random Description
And I fill in a random Project Name
And I fill in a random Project Description
And I fill in a random Project Code (and remember it)
And I set Project Manager Principal Name to a Project Manager
And I set Chart Code to a valid chart code
And I set Organization Code to a valid org code
And I submit the document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
Same goes with all of
these guys.
Given I am logged in as an Administrator
And I submit a new project code maintenance document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
Given I am logged in as an Administrator
And I submit a new project code maintenance document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then it should go to a Final Status
Example - Yikes!
What should go to a final status?
Remember, step definitions are
“global.”
Given I am logged in as an Administrator
And I submit a new project code maintenance document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then the project code maintenance document’s status should be final
Example - Yikes?
Given I am logged in as an Administrator
And I submit a new project code maintenance document
And I acknowledge the document as the first reviewer
When I acknowledge the document as the second reviewer
Then the project code maintenance document’s status should be final
Example - Getting better
Not bad! But it can still be better...
Given an Administrator submits a new project code maintenance document
When first and second reviewers acknowledge the project code maintenance document
Then the project code maintenance document’s status should be final
Example - Ahhhhh... Much better
● Cucumber adds value when abstracted from the code
● Scenarios should:
○ Model user behavior
○ Validate something important to the user
● Avoid:
○ Excessive detail and specificity
○ UI references (“click”, “field”, “page”, etc.)
○ Being too generic
● Final thought: Read The Cucumber Book
Summary

More Related Content

Viewers also liked (8)

PPTX
Behavior Driven Development - TdT@Cluj #15
Tabăra de Testare
 
KEY
Week7
reneedv
 
KEY
Ruby Testing: Cucumber and RSpec
James Thompson
 
PPT
Android testing calabash
kellinreaver
 
PDF
RSpec と Cucumber
Masahiro Tomita
 
PDF
Athens Ruby meetup #8
teoulas
 
PPTX
Cucumber From the Ground Up - Joseph Beale
QA or the Highway
 
PDF
Rails course day 8
Al Sayed Gamal
 
Behavior Driven Development - TdT@Cluj #15
Tabăra de Testare
 
Week7
reneedv
 
Ruby Testing: Cucumber and RSpec
James Thompson
 
Android testing calabash
kellinreaver
 
RSpec と Cucumber
Masahiro Tomita
 
Athens Ruby meetup #8
teoulas
 
Cucumber From the Ground Up - Joseph Beale
QA or the Highway
 
Rails course day 8
Al Sayed Gamal
 

Similar to Writing Cucumber (20)

PPTX
How to Write Great User Stories Today.pptx
AlanJamisonMBASPC
 
PDF
Acceptance Criteria
Jeff Kosciejew
 
DOCX
Employment History
Sushma Hazari
 
PDF
Getting it right from the start
Jon Fukuda
 
DOC
ChrisGarrisonFeatherweightArchitecture-DetailDesign
Chris Garrison
 
PPT
Revolutionizing the hypatia metadata experience
Kat Chuang
 
PPTX
Project Management for Mobile/#MWeb2014/Aheibel
Amy Heibel
 
PPT
Developing a Culture of Quality Code (Midwest PHP 2020)
Scott Keck-Warren
 
PDF
Acceptance test plan_4-24-07
Virgiawan Lakstianto
 
PDF
User Stories Writing - Codemotion 2013
Fabio Armani
 
PDF
User stories writing - Codemotion 2013
Stefano Leli
 
PPTX
DMDS Winter Workshop 2 Slides
Paige Morgan
 
PDF
FMK2019 being an optimist in a pessimistic world by vincenzo menanno
Verein FM Konferenz
 
KEY
Project management
Creech
 
PDF
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
ClarkTony
 
PDF
Paul Capello Cerner Health Conference
tigcap
 
PDF
Paul Capello CHC 2010 Final
tigcap
 
DOCX
Question One (at least 200Wodrs).docx
makdul
 
PPTX
Behavior Driven Development
Liz Keogh
 
PPTX
Ian wcre2011
SAIL_QU
 
How to Write Great User Stories Today.pptx
AlanJamisonMBASPC
 
Acceptance Criteria
Jeff Kosciejew
 
Employment History
Sushma Hazari
 
Getting it right from the start
Jon Fukuda
 
ChrisGarrisonFeatherweightArchitecture-DetailDesign
Chris Garrison
 
Revolutionizing the hypatia metadata experience
Kat Chuang
 
Project Management for Mobile/#MWeb2014/Aheibel
Amy Heibel
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Scott Keck-Warren
 
Acceptance test plan_4-24-07
Virgiawan Lakstianto
 
User Stories Writing - Codemotion 2013
Fabio Armani
 
User stories writing - Codemotion 2013
Stefano Leli
 
DMDS Winter Workshop 2 Slides
Paige Morgan
 
FMK2019 being an optimist in a pessimistic world by vincenzo menanno
Verein FM Konferenz
 
Project management
Creech
 
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
ClarkTony
 
Paul Capello Cerner Health Conference
tigcap
 
Paul Capello CHC 2010 Final
tigcap
 
Question One (at least 200Wodrs).docx
makdul
 
Behavior Driven Development
Liz Keogh
 
Ian wcre2011
SAIL_QU
 
Ad

Writing Cucumber

  • 3. ● Feature ● Summary ● Scenario Cucumber’s Parts
  • 4. ● Feature ● Summary ● Scenario Cucumber’s Parts “What is the point?” “Why is this a feature?” “Who is going to care?”
  • 5. ● We are all QA ● If it’s not readable no one will read it ● “Living” requirements documentation ● Ubiquitous language Theme: Effective Communication Why “Readable” Cucumber?
  • 6. Write a scenario without thinking about... ● User Interface ● The needs of the Ruby code Instead, pretend you’re talking to a SME (Be okay with getting it wrong the first time, because you will) The Basic Approach
  • 7. Ask yourself this question: “If the entire system were scrapped and re-written from scratch, what is the likelihood that this Feature/Scenario would survive in its present form?” The Basic Approach
  • 8. Unit Tests ● Fields allowing certain character sets ● Select lists containing expected values ● Document IDs unique User Interface Tests ● Element alignments ● Usability considerations Performance Tests ● Page loading ● Server calls Cucumber is not suited for...
  • 9. I create a proposal Declarative versus Imperative I go to the login page I enter my user name I enter my password I click the login button I click the “Create Proposal” link I click the “expand all” button I type “Title” in the title field I select “New” in the Type selection list I type “00340” in the Sponsor Code field I type today’s date into the Start Date field I type tomorrow’s date into the End Date field I click on the save button ...
  • 10. I create a proposal Declarative In Detail in the BL-BL unitwith a 5-year budgetwith a Federal sponsorwithout a PIstarting next yearhaving a sponsor deadline
  • 11. Given a particular system state When a specific event occurs Then a new state is expected ● Everything needed for the test/requirement to be valid is spelled out concisely ● Everything not needed is left out ● The point is explicit ● The expected/desired outcome is comprehensible ● Remember that the user has some goal in mind--some reason for using the software Given/When/Then
  • 12. Scenario: Create Proposal with Invalid Sponsor Given a user exists with the role Proposal Creator When the proposal creator creates a proposal with an invalid sponsor Then an error should say that a valid sponsor is required Scenario: Adding an F&A rate to an Award Given a User exists with the role Award Modifier And the Award Modifier creates an Award When the Award Modifier adds an F&A rate to the Award Then the default start and end dates are based on the F&A rate's fiscal year Scenario: Protocol submitted to a Committee with submission date restrictions Given users exist with the roles IRB Administrator and Protocol Creator And the IRB Admin submits a committee with events scheduled before and after its adv submission days setting And the Protocol Creator creates an IRB Protocol in the committee's home unit When the Protocol is being submitted to the committee for review Then the earliest available schedule date is based on the committee's Adv Submission Days value Examples - Scenario Title
  • 13. Given I am logged in as "@PersonX@" And I attempt to view the portal page When I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to "@project_code.project-manager-principal@" And I set Chart Code to "@project_code.chart-code@" And I set Organization Code to "@project_code.org-code@" And I submit the document And I acknowledge the document as "@project_code.reviewer1@" And I acknowledge the document as "@project_code.reviewer2@" Then it should go to a Final Status Example - Yikes!
  • 14. Given I am logged in as "@PersonX@" And I attempt to view the portal page When I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to "@project_code.project-manager-principal@" And I set Chart Code to "@project_code.chart-code@" And I set Organization Code to "@project_code.org-code@" And I submit the document And I acknowledge the document as "@project_code.reviewer1@" And I acknowledge the document as "@project_code.reviewer2@" Then it should go to a Final Status Example - Yikes! Only “@PersonX@”??? Seems like this, and the other “@” lines are sneaky bits of code, which is a no-no at the Scenario level!
  • 15. Given I am logged in as an Administrator And I attempt to view the portal page When I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer And I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes!
  • 16. Given I am logged in as an Administrator And I attempt to view the portal page When I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer And I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes! How do you code for an “attempt”? Why is “viewing” the portal page important for this scenario?
  • 17. Given I am logged in as an Administrator And I attempt to view the portal page When I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer And I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes!
  • 18. Given I am logged in as an Administrator When I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer And I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes! What is the pivotal, state-changing event in this scenario?
  • 19. Given I am logged in as an Administrator And I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes!
  • 20. Given I am logged in as an Administrator And I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes! Why isn’t every bit of data in the test being remembered automatically? Is it really important to explicitly state this stuff in the scenario? Also, these steps seem dangerously vague. Will they always work?
  • 21. Given I am logged in as an Administrator And I access the Project Code maintenance document And I fill in a random Description And I fill in a random Project Name And I fill in a random Project Description And I fill in a random Project Code (and remember it) And I set Project Manager Principal Name to a Project Manager And I set Chart Code to a valid chart code And I set Organization Code to a valid org code And I submit the document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes! Same goes with all of these guys.
  • 22. Given I am logged in as an Administrator And I submit a new project code maintenance document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes!
  • 23. Given I am logged in as an Administrator And I submit a new project code maintenance document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then it should go to a Final Status Example - Yikes! What should go to a final status? Remember, step definitions are “global.”
  • 24. Given I am logged in as an Administrator And I submit a new project code maintenance document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then the project code maintenance document’s status should be final Example - Yikes?
  • 25. Given I am logged in as an Administrator And I submit a new project code maintenance document And I acknowledge the document as the first reviewer When I acknowledge the document as the second reviewer Then the project code maintenance document’s status should be final Example - Getting better Not bad! But it can still be better...
  • 26. Given an Administrator submits a new project code maintenance document When first and second reviewers acknowledge the project code maintenance document Then the project code maintenance document’s status should be final Example - Ahhhhh... Much better
  • 27. ● Cucumber adds value when abstracted from the code ● Scenarios should: ○ Model user behavior ○ Validate something important to the user ● Avoid: ○ Excessive detail and specificity ○ UI references (“click”, “field”, “page”, etc.) ○ Being too generic ● Final thought: Read The Cucumber Book Summary