more than automation - how good acceptance tests can make your team happier

53
More than automation How good acceptance tests can make your team happier @mattwynne Freelance Programmer & Coach Wednesday, 18 April 12

Upload: seleniumconf

Post on 14-Dec-2014

1.780 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

More than automationHow good acceptance tests can make your team happier

@mattwynneFreelance Programmer & Coach

Wednesday, 18 April 12

Page 2: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Refuctoring your Cucumber tests

Protecting your job with Mortgage Driven Development

@mattwynneFreelance Programmer & Coach

Wednesday, 18 April 12

Page 3: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

What is MDD?

Wednesday, 18 April 12

Page 4: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

MDD Core Principles

Maintainable code offers no

job security

Programming should be a

solitary activity

Wednesday, 18 April 12

Page 5: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Wednesday, 18 April 12

Page 6: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

MDD FAIL

http://www.flickr.com/photos/downtree/1666035170/

Wednesday, 18 April 12

Page 7: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

MDD WIN ✔

http://www.flickr.com/photos/chokingsun/3535556349/

Wednesday, 18 April 12

Page 8: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Maintainable code offers no

job security

therefore

As a mortgage-driven developer,I try to make my code seem as

weird and mysterious as possible

Wednesday, 18 April 12

Page 9: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Programming should be a

solitary activity

therefore

As a mortgage-driven developer,I make the experience of collaborating

with me as awkward and unpleasant as I can*

* without actually getting fired

Wednesday, 18 April 12

Page 10: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Cucumber is a

threatWednesday, 18 April 12

Page 11: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Cucumber Could lead to YOUR house

being repossessed

Wednesday, 18 April 12

Page 12: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Cucumber is a threat

• Promotes collaboration between stakeholders and developers

• Transparency of how the system actually behaves

• Aims to develop a shared understanding or ubiquitous language within the team

Wednesday, 18 April 12

Page 13: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

MDD Core Practice

Refuctoring

Wednesday, 18 April 12

Page 14: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

What is Refuctoring?"Refuctoring is the process of taking a well-designed piece of code and, through a series of small, reversible changes, making it completely unmaintainable by anybody except yourself."

http://www.waterfall2006.com/gorman.html

Wednesday, 18 April 12

Page 15: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up

Sign up works in three stages:

1. Apply for an account via a form on the website. Applicant gets an email. 2. Follow the confirmation in the email to activate the account. 3. Fill out profile information. By this stage the user has an account but we try to collect more information about them.

Scenario: Apply for an account Given I do not have an account When I follow the sign up link from the homepage And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email

Scenario: Confirm account Given I have applied for an account And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile

Scenario: Fill out account profile Given I have logged in to a brand new account When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 16: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Step 1: Remove Spurious Documentation

Wednesday, 18 April 12

Page 17: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up

Sign up works in three stages:

1. Apply for an account via a form on the website. Applicant gets an email. 2. Follow the confirmation in the email to activate the account. 3. Fill out profile information. By this stage the user has an account but we try to collect more information about them.

Scenario: Apply for an account Given I do not have an account When I follow the sign up link from the homepage And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email

Scenario: Confirm account Given I have applied for an account And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile

Scenario: Fill out account profile Given I have logged in to a brand new account When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 18: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up

Scenario: Apply for an account Given I do not have an account When I follow the sign up link from the homepage And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email

Scenario: Confirm account Given I have applied for an account And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile

Scenario: Fill out account profile Given I have logged in to a brand new account When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 19: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Step 2: Conflate Scenarios

Wednesday, 18 April 12

Page 20: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up

Scenario: Apply for an account Given I do not have an account When I follow the sign up link from the homepage And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email

Scenario: Confirm account Given I have applied for an account And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile

Scenario: Fill out account profile Given I have logged in to a brand new account When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 21: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account When I follow the sign up link from the homepage And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email When I have confirmed my application And I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 22: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Step 3: Insert Incidental Detail

Wednesday, 18 April 12

Page 23: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account When I follow the sign up link from the homepage And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 24: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" And I fill out the form with valid details and submit it Then I should see a confirmation message telling me to check my email And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 25: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" When I fill in "user_email" with "[email protected]" And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "passw0rd" And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith" And I fill in "user_display_name" with "Dave Smith" And I fill in "user_organisation_name" with "Big Corp" And I fill in "user_city" with "London" And I select "United Kingdom" from "user_country_id" And I fill in "user_phone_number" with "1234 5678" And I press "Sign up" Then I should see a confirmation message telling me to check my email And I have confirmed my application When I log in Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 26: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" When I fill in "user_email" with "[email protected]" And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "passw0rd" And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith" And I fill in "user_display_name" with "Dave Smith" And I fill in "user_organisation_name" with "Big Corp" And I fill in "user_city" with "London" And I select "United Kingdom" from "user_country_id" And I fill in "user_phone_number" with "1234 5678" And I press "Sign up" Then I should see "You have signed up successfully" Given I have confirmed my signup for "[email protected]" And I login as "[email protected]" Then I should not see a message telling me to confirm my account But I should see a welcome message And I should see a form asking me to fill out my account profile When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 27: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" When I fill in "user_email" with "[email protected]" And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "passw0rd" And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith" And I fill in "user_display_name" with "Dave Smith" And I fill in "user_organisation_name" with "Big Corp" And I fill in "user_city" with "London" And I select "United Kingdom" from "user_country_id" And I fill in "user_phone_number" with "1234 5678" And I press "Sign up" Then I should see "You have signed up successfully" Given I have confirmed my signup for "[email protected]" And I login as "[email protected]" And I should not see "You have to confirm your account before continuing" And I should see "Thank you for signing up for the portal" And I should see "Home / New Demographic" And I should see a form asking me to fill out my account profile When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 28: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" When I fill in "user_email" with "[email protected]" And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "passw0rd" And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith" And I fill in "user_display_name" with "Dave Smith" And I fill in "user_organisation_name" with "Big Corp" And I fill in "user_city" with "London" And I select "United Kingdom" from "user_country_id" And I fill in "user_phone_number" with "1234 5678" And I press "Sign up" Then I should see "You have signed up successfully" Given I have confirmed my signup for "[email protected]" And I login as "[email protected]" And I should not see "You have to confirm your account before continuing" And I should see "Thank you for signing up for the portal" And I should see "Home / New Demographic" And I should see "I am a:" And I should see "My Main Work Area is:" And I should see "I work with:" And I should see "About your organisation" And I should see "The primary area is:" And I should see "The secondary area is:" And I should see "Your Reasons for joining this community" When I fill out my profile details And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 29: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign Up Scenario: Apply for an account Given I do not have an account And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" When I fill in "user_email" with "[email protected]" And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "passw0rd" And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith" And I fill in "user_display_name" with "Dave Smith" And I fill in "user_organisation_name" with "Big Corp" And I fill in "user_city" with "London" And I select "United Kingdom" from "user_country_id" And I fill in "user_phone_number" with "1234 5678" And I press "Sign up" Then I should see "You have signed up successfully" Given I have confirmed my signup for "[email protected]" And I login as "[email protected]" And I should not see "You have to confirm your account before continuing" And I should see "Thank you for signing up for the portal" And I should see "Home / New Demographic" And I should see "I am a:" And I should see "My Main Work Area is:" And I should see "I work with:" And I should see "About your organisation" And I should see "The primary area is:" And I should see "The secondary area is:" And I should see "Your Reasons for joining this community" And I should see "Demographic was successfully created" And I should see "I am a: Researcher" And I should see "My Main Work Area is: Heart Disease" And I should see "My Organisations primary area is: Equipment Manufacturer" And I log out and log in again Then I should not see the form asking me to fill out my account profile

Wednesday, 18 April 12

Page 30: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: Sign up Scenario: Apply for an Account Given I have setup the base data And I am on the home page And I follow "Join" Then I should see "we need some information from you." And I should see "Home / Join" When I fill in "user_email" with "[email protected]" And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "passw0rd" And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith" And I fill in "user_display_name" with "Dave Smith" And I fill in "user_organisation_name" with "Big Corp" And I fill in "user_city" with "London" And I select "United Kingdom" from "user_country_id" And I fill in "user_phone_number" with "1234 5678" And I press "Sign up" Then I should see "You have signed up successfully" Given I have confirmed my signup for "[email protected]" And I login as "[email protected]" And I should not see "You have to confirm your account before continuing" And I should see "Thank you for signing up for the portal" And I should see "Home / New Demographic" And I should see "I am a:" And I should see "My Main Work Area is:" And I should see "I work with:" And I should see "About your organisation" And I should see "The primary area is:" And I should see "The secondary area is:" And I should see "Your Reasons for joining this community" Then I select "Researcher" from "I am a:" Then I select "Heart Disease" from "My Main Work Area is:" Then I select "Equipment Manufacturer" from "The primary area is:" Then I press "Save Demographic Information" And I should see "Demographic was successfully created" And I should see "I am a: Researcher" And I should see "My Main Work Area is: Heart Disease" And I should see "My Organisations primary area is: Equipment Manufacturer" Then I am signed out And I login as "[email protected]" And I should not see "Home / New Demographic"

Refuctored

!

Wednesday, 18 April 12

Page 31: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Incidental Detail

Conflated Scenarios

Brittle Tests

Reader Confusion

Reader Boredom

Job Security

Wednesday, 18 April 12

Page 32: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

MDD Best Practices

• Include as much irrelevant detail in your features as possible

• keeps them hard / boring to read

• and nice and brittle

• Try to sprinkle technical details like CSS or HTML in there too

Wednesday, 18 April 12

Page 33: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Now that I have your attention

Wednesday, 18 April 12

Page 34: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Wednesday, 18 April 12

Page 35: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Think about it

• Why are you writing these features?

Wednesday, 18 April 12

Page 36: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

What you think you

need

All you actually need

Wednesday, 18 April 12

Page 37: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

What would give you some value,

right now

What you think you

need

All you actually need

Wednesday, 18 April 12

Page 38: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Think about it

• Who are you writing these features for?

Wednesday, 18 April 12

Page 39: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Ideas

Features

Code

IdeasIdeas

Wednesday, 18 April 12

Page 40: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Are you writing tests or documentation?

Wednesday, 18 April 12

Page 41: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Mea culpa

Wednesday, 18 April 12

Page 42: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. It is recommended to regenerate this file in the future when you upgrade to a newer version of cucumber-rails. Consider adding your own code to a new file instead of editing this one.

Wednesday, 18 April 12

Page 43: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Wednesday, 18 April 12

Page 44: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Levels of Abstraction

Wednesday, 18 April 12

Page 45: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Imperative

DeclarativeWhen I fill out the form with valid details

When I fill in "user_email" with "[email protected]"

And I fill in "user_password" with "passw0rd"

And I fill in "user_password_confirmation" with "passw0rd"

And I fill in "user_title" with "Mr"And I fill in "user_firstname" with "Dave"And I fill in "user_surname" with "Smith"

Wednesday, 18 April 12

Page 46: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Feature: The System

Scenario: Everything Works Given the system exists When I use it Then it should work, perfectly

Wednesday, 18 April 12

Page 47: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Whose domain is it anyway?

Wednesday, 18 April 12

Page 48: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Solutions

• Feedback

• Feedback

• Feedback

Wednesday, 18 April 12

Page 49: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Wednesday, 18 April 12

Page 50: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Relish Features

• Private projects, organisations

• Full text search

• Editorial

• Markdown pages

• Navigation / ToC ordering

• Push from a gem

Wednesday, 18 April 12

Page 51: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Other Tips

• Strive for documentation, not tests

• Write scenarios with domain experts

• Pair up with programmers to write step definitions

• Banish incidental details!

Wednesday, 18 April 12

Page 52: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Thanks

Wednesday, 18 April 12

Page 53: More Than Automation - How Good Acceptance Tests Can Make Your Team Happier

Further Reading

• http://dhemery.com/pdf/writing_maintainable_automated_acceptance_tests.pdf

• http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html

• http://dannorth.net/2011/01/31/whose-domain-is-it-anyway

• http://elabs.se/blog/15-you-re-cuking-it-wrong

• http://github.com/mattwynne/cucumber-usual_suspects

• http://github.com/riverGlide/CukeSalad/

• http://relishapp.com

• http://blog.mattwynne.net

Wednesday, 18 April 12