atdd by example with cucumber
TRANSCRIPT
A C C E P TA N C E T E S T D R I V E N D E V E L O P M E N TB Y E X A M P L E W I T H C U C U M B E R
W H O W E A R E .
@ D O U G M O R G A N _G I T H U B . C O M / D M O R G A N 3 4 0 5D O U G M O R G A N
W O R K I N G A G R E E M E N T S
• Help each other out. • You aren't done until the person next to you is done.
• Time boxed breaks. • Respect your peers; please don't be late.
• Ask questions. • Speak up if you don't understand something.
M O R N I N G A G E N D A
• Acceptance Test Driven Development • Why? • What?
• Shared Understanding/ Collaboration • Three Amigos • Acceptance Criteria • Gherkin • Cucumber
A F T E R N O O N A G E N D A
• PageObject • Interacting with a web browser • Cleaner scenarios • Asserting requirements
• Q & A
W H Y AT D D ?F I R S T O F F.
W H Y AT D D ?
T >
^
F
X
W H Y AT D D ?
• Clear definition of done • Over building. • Under building.
• Avoiding Rework • Due to not understanding requirements.
• Avoid Context Switching
R E D U C E W A S T E .B A S I C A L LY.
W H AT I S AT D D ?
Acceptance Test Driven Development
– M E R R I A M - W E B S T E R D I C T I O N A R Y
“The quality or state of being accepted or acceptable”
Copyright LeanDog, Inc. All Rights Reserved. Do not copy or distribute without permission.
Ready Development Test Review Done
Product Owner
Developer Tester
Copyright LeanDog, Inc. All Rights Reserved. Do not copy or distribute without permission.
Ready Development Test Review Done
Product Owner
Developer Tester
Meeting
?Done
TrackingPriority
Not
Done Done
UX
DoneNot
DoneNot
Done
W A S T E .R E W O R K R E S U LT S I N
S H A R E D U N D E R S TA N D I N G
DeveloperProduct Owner
Tester
M U LT I P L E P E R S P E C T I V E S
S H A R E D U N D E R S TA N D I N G
Written words are the second worst form of
communication
S H A R E D U N D E R S TA N D I N G
3030
1. 2.
3. 4.
"I'm glad we all agree"
"Ah!" "I'm glad we're all agreed then"
"Ah!"
"Crystal Clear: A Human-Powered Methodology for small teams" By Alistair Cockburn
Information Radiators Invented around the year 2000 by Alistair Cockburn
Clear Communication
*The Agile Samurai - Jonathan Rasmusson
S H A R E D U N D E R S TA N D I N G
DeveloperProduct Owner
Tester
¡Arriba!
T H E “ T H R E E A M I G O S ”
G H E R K I N S Y N TA X
Feature: …
Scenario: … Given … When … And … Then …
S H A R E D U N D E R S TA N D I N G
S H A R E D U N D E R S TA N D I N G
S H A R E D U N D E R S TA N D I N G
As a credit card paying customer,
I want to be informed when the credit card
information I have entered is in an invalid format.
So that I can correct my information and successfully complete
my transaction.
S H A R E D U N D E R S TA N D I N G
Feature: Entering credit card information
Scenario: Credit card number too short
Scenario: Expiration date invalid
S H A R E D U N D E R S TA N D I N G
Scenario: Credit card number too short Given I have chosen some items to buy And I am about to enter my credit card details When I enter a card number that's only 15 digits long Then I expect the page to be redisplayed And I expect to see “Credit card must be at least 16 digits”
S H A R E D U N D E R S TA N D I N G
Scenario: Expiration date invalid Given I have chosen some items to buy And I am about to enter my credit card details When I enter a card expiration date that's in the past Then I expect the page to be redisplayed And I expect to see “Incorrect expiration date”
brushtoothpaste
bristles water
Varieties of Language in Cucumber Scenarios
TA U T O L O G I C A L
Scenario: Search for a Book When I search for a book Then I should see the correct results
S U P E R T E C H N I C A L
Scenario: Search for a book Given the following Authors: | id | name | | 1 | Charles Dickens | | 2 | John Steinbeck | | 3 | Fyodor Dostoyevsky | And the following Titles: | id | title | author_id | | 1 | A Tale of Two Cities | 1 | | 2 | Crime and Punishment | 3 | | 3 | East of Eden | 2 | And I'm on "http://www.bookstore.biz/" When I fill in "Dickens" in "//input[name()='q']" And I click "#searchButton" Then there should be 1 "div.book div.title" element And the page should contain "A Tale of Two Cities"
S C R I P T Y, W I T H I M P L E M E N TAT I O N D E TA I L S
Scenario: Search for a book Given the following catalog: | Title | Author | | A Tale of Two Cities | Charles Dickens | | Crime and Punishment | Fyodor Dostoyevsky | | East of Eden | John Steinbeck | And I'm on the bookstore home page When I fill in "Dickens" in the search field And I click "Search" Then I should see only "A Tale of Two Cities" in the results
E X A M P L E I N D O M A I N L A N G U A G E
Scenario: Search for a book Given the following catalog: | Title | Author | | A Tale of Two Cities | Charles Dickens | | Crime and Punishment | Fyodor Dostoyevsky | | East of Eden | John Steinbeck | When I search for "Dickens" Then I should see only "A Tale of Two Cities" in the results
E X A M P L E I N D O M A I N L A N G U A G E W I T H E X C E S S D E TA I L
Scenario: Search for a book Given the following catalog: | Title | Author | Publisher | ISBN | | A Tale of Two Cities | Charles Dickens | Qualitas Classics| 1897093594 | | Crime and Punishment | Fyodor Dostoyevsky| Simon & Brown | 1936041030 | | East of Eden | John Steinbeck | Penguin | 0142000655 | When I search for "Dickens" Then I should see only the following in the results: | Title | Author | Format | Price | | A Tale of Two Cities | Charles Dickens | Paperback | $14.90 |
D I F F E R E N T K I N D S O F S C E N A R I O STa
utolog
iDom
ain La
ngua
ge
Domain
Lang
uage
Im
plemen
tation
Sup
er
Sweet
E X E R C I S E
Identify different kinds of scenarios
Acceptance Test Driven Development
W H E N S H O U L D W E T E S T O U R C O D E ?
TestCode
Code TestMonths
Code TestWeeks
Code TestDays
W H E N S H O U L D W E T E S T O U R C O D E ?
S T O R Y T W O
Code TestS T O R Y O N E
S T O R Y T W O
S T O R Y T W OContext Switching
S T O R Y O N E
R E W O R K
S T O R Y O N E
R E W O R K
C O N T E X T - S W I T C H I N G
= WA S T E .
W H E N S H O U L D W E T E S T O U R C O D E ?
Write Test
Run Test
Code Run Test
Run Test
Run Test
T E S T D R I V E N
1. Red - Write a failing test.
2. Green - Write code to make the test pass.
3. Refactor - Preserve the behavior. - Clean up the code.
http://stackoverflow.com/questions/28372861/cucumber-js-for-bdd-unit-testing
L E T S G E T T O W O R K !
https://github.com/dmorgan3405/ATDD-By-Example.git
git clone
D E M O
• Open the browser
• Navigate to puppies.herokuapp.com
• Close the browser
Checkpoint: example_of_driving_a_browser
PA R T D E U XA C C E P TA N C E T E S T D R I V E N D E V E L O P M E N T
W O R K I N G A G R E E M E N T S ( R E M I N D E R )
• Help each other out. • You aren't done until the person next to you is done.
• Time boxed breaks. • Respect your peers; please don't be late.
• Ask questions. • Speak up if you don't understand something.
T O O L B E LT
C O M M O N LY U S E D R U B Y G E M S
• cucumber • watir-webdriver • page-object • rspec • nokogiri • active-record • factory_girl • savon • data_magic
PA G E O B J E C T
“A simple gem that assists in creating flexible page objects for testing browser based applications. The goal is to facilitate creating abstraction layers in your tests to decouple the tests from the item they are testing and to provide a simple interface to the elements on a page. It works with both watir-webdriver and selenium-webdriver.”
* W W W. G I T H U B . C O M / C H E E Z Y / PA G E - O B J E C T / B L O B / M A S T E R / R E A D M E . M D
P I C K A B R O W S E R
• Firefox • Nothing extra is needed.
• Chrome • Driver needed. (https://sites.google.com/a/chromium.org/chromedriver/downloads)
• Put in path.
• Internet Explorer • Driver needed. • Security Zones protection setting need to be the same. • Zoom set to 100%.
PA G E O B J E C T A P I
Use the Quick reference guide inside of the repository!
PA G E FA C T O R Y
To visit a page, then preform the action use
visit_page(HomePage).action_to_do
or
visit_page(HomePage) do |page| page.action_to_do end
PA G E FA C T O R Y
To preform the action on the current page
on_page(HomePage).action_to_do
or
on_page(HomePage) do |page| page.action_to_do end
L E T S A D O P T A P U P P Y !
L E T S A D O P T A P U P P Y !
Feature: Adopting a puppy
As a puppy lover I want to adopt puppies So that ...
Background: Given I am on the puppy adoption site
Scenario: Adopting a puppy When I view the details of the first puppy And I choose to adopt the puppy And I enter my name "Your Name Here" And I enter my address "1151 N Marginal Rd" And I enter my email "[email protected]" And I choose to pay by "Credit card" And I choose to place my order Then I should see "Thank you for adopting a puppy!"
Checkpoint: start_adopting_a_puppy
A D D I N G V E R I F I C AT I O N
How would you verify the thank you message is displayed?
Checkpoint: example_of_adding_verification
W I T H C U C U M B E R TA B L E SH I G H E R L E V E L T E S T S
Cucumber::MultilineArgument::DataTable
#hashes
Returns Array of Hashes
Checkpoint: start_using_cucumber_tables
P O P U L AT E PA G E W I T H
This method will populate all matched page elements from the Hash passed as an argument.
• TextFields • TextAreas • SelectLists • FileFields • Checkboxes • Radio Buttons
The way it find an element is by matching the Hash key to the name you provided when declaring the element on your page.
P O P U L AT E PA G E W I T H
class ExamplePage include PageObject
text_field(: name, :index => 0)
FORM_DATA = {:name => ‘Test User’}
def fill_form populate_page_with(FORM_DATA) end
end
Checkpoint: example_of_using_populate_page_with
D ATA M A G I C
An easy to use gem that provides datasets that can be used by your application and tests. The data is stored in yaml files.
Checkpoint: example_of_data_magic
N O W L E T S A D O P T T W O P U P P I E S !
Feature: Adopting multiple puppies
As a puppy lover I want to adopt multiple puppies So that ...
Background: Given I am on the puppy adoption site
Scenario: Adopting multiple puppies When I adopt puppy 1 And I choose to adopt another puppy And I adopt puppy 2 And I choose to complete the adoption And I checkout Then I should see "Thank you for adopting a puppy!"
Checkpoint: start_adopting_two_puppies
S C E N A R I O O U T L I N E S
Checkpoint: start_using_scenario_outlines
Scenario Outline: Shopping cart offers common accessories When I adopt puppy 1 Then I should see "<accessory>" as an optional accessory Examples: | accessory | | Collar & Leash | | Chew Toy | | Travel Carrier | | First Vet Visit |
TA B L E VA L I D AT I O N S
What should we tests?
TA B L E VA L I D AT I O N S
• Verify one name, puppy price and cart total.
***Bonus***
• Verify two names, puppy prices, and cart total.
Checkpoint: start_validating_shopping_cart
Q U E S T I O N S ?Q & A
T H A N K Y O U !
Jeff Morgan @chzy github.com/cheezy
Doug Morgan @dougmorgan_ github.com/dmorgan3405