living with acceptance tests: beyond write-once (xp nyc)
TRANSCRIPT
Living with
Acceptance Tests:
Beyond Write-Once
Daniel Wellman
Twitter: @wellman
E-mail: [email protected]
XP NYC #xpnycFebruary 10, 2015
New Project
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance Test
End-to-End
Acceptance TestEnd-to-End
Acceptance Test
End-to-End
Acceptance TestEnd-to-End
Acceptance Test
End-to-End
Acceptance Test
Example: Fraud Protection
for an Amazon-like store
Example from Gojko Adzic, “Specification by Example”
Given a user with no previous transaction history,
And the user’s account registration country is the UK,
When the user places an order with delivery country U.S.,
Then the transaction is marked as suspicious,
But the user sees order status as “Pending.”
Before: End-to-EndWhen(/^the user places an order with
delivery country (.*),$/) do |country_name|
end
# ...
fill_in 'Address', with: ...
select country_name, from: 'Country Selector’
click_button 'Ship To This Address'
expect(page).to have_content
'Your order has been placed’
# ...
After: Using Domain Model
When(/^the user places an order with
delivery country (.*),$/) do |country_name|
end
# ...
country = Country.new(country_name)
order = Order.new( ...,
ship_to : Address.new(
street: ...,
country: country))
sales_clerk.accept(order)
# ...
Alternate Steps:
Use Conditionals
When(/^the user places an order with
delivery country (.*),$/) do |country_name|
if use_browser
# drive a browser using Capybara; slower
else
# use domain objects; faster
end
end
use_browser = ENV['USE_BROWSER_FOR_TESTS']
Imperative Style
Given I am on the registration page,
And I enter "UK" as my billing country,
And I press the "Register" button,
And I add an item to my cart,
When I checkout
And I enter "U.S." as my shipping country,
And ...
Declarative Style
Given a user with no previous transaction history,
And the user’s account registration country is the UK,
When the user places an order with delivery country U.S.,
Then the transaction is marked as suspicious,
But the user sees order status as “Pending.”
Example by Gojko Adzic, “Specification by Example”
You can’t tell how these are implemented!
Suggestions
• Maintain your acceptance tests just like production
code
• Write tests which describe what, not how, so their
implementations can easily evolve later
• Decide when you can start moving acceptance
tests from end-to-end to using the domain directly
• Re-evaluate your product’s tests and testing
strategy as your system grows
Photo Credits“HighLine_061409_2779” by Jessica Sheridan is licensed under CC BY 2.0
“Highline New York” by Rebecca Krebs is licensed under CC BY 2.0
“NYC: The Highline" by Wally Gobetz is licensed under CC BY-NC-ND 2.0
“Rot”, “Yellow Cart”, and “Many Hands Make Light Work” by Oliver Rich are licensed
under CC BY-NC-ND 2.0
“highline-1010384.jpg” by keroism is licensed under CC BY-SA 2.0
“highline” by Elijah Porter is licensed under CC BY-NC-SA 2.0
“Highline_030” by Timothy Vogel is licensed under CC BY-NC 2.0
“201106073451_DSC_0014_1.JPG” by Leonel Ponce is licensed under CC BY-NC 2.0
“193” by verndogs is licensed under CC BY-NC 2.0
Living with
Acceptance Tests:
Beyond Write-Once
Daniel Wellman
Twitter: @wellman
E-mail: [email protected]
XP NYC #xpnycFebruary 10, 2015