Slide 1

Slide 1 text

Forget the tools! When Cucumbers go bad @mattwynne Freelance Programmer & Coach Turku Agile Day, May 2012

Slide 2

Slide 2 text

Refuctoring your Cucumber tests Protecting your job with Mortgage Driven Development @mattwynne Freelance Programmer & Coach

Slide 3

Slide 3 text

What is MDD?

Slide 4

Slide 4 text

MDD: Core principles Maintainable code offers no job security Programming should be a solitary activity

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

MDD WIN ✔ http://www.flickr.com/photos/chokingsun/3535556349/

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Cucumber is a threat

Slide 11

Slide 11 text

BDD Could lead to your house being repossessed

Slide 12

Slide 12 text

Why 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

Slide 13

Slide 13 text

MDD: Core practice Refuctoring

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Step 1: Remove spurious documentation

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Step 2: Conflate scenarios

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Step 3: Insert incidental detail

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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 !

Slide 31

Slide 31 text

Incidental Detail Conflated Scenarios Brittle Tests Reader Confusion Reader Boredom Job Security

Slide 32

Slide 32 text

MDD: Best practices • Include as much irrelevant detail in your features as possible • keeps them boring to read • and nice and brittle • Avoid using words you hear business people using. Invent your own instead!

Slide 33

Slide 33 text

Now that I have your attention

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Think about it • Why are you using this tool?

Slide 36

Slide 36 text

"The hardest single part of building a software system is deciding what to build" -- Fred Brooks

Slide 37

Slide 37 text

What you think you need All you actually need

Slide 38

Slide 38 text

What would give you some value, right now What you think you need All you actually need

Slide 39

Slide 39 text

Ideas Examples Code Ideas Ideas

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Are you writing tests or documentation?

Slide 43

Slide 43 text

Mea culpa

Slide 44

Slide 44 text

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.

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Levels of abstraction

Slide 47

Slide 47 text

Imperative Declarative When I fill out the form with valid details When I fill in "user_email" with "dave123@hotmail. And I fill in "user_password" with "passw0rd" And I fill in "user_password_confirmation" with "pa And I fill in "user_title" with "Mr" And I fill in "user_firstname" with "Dave" And I fill in "user_surname" with "Smith"

Slide 48

Slide 48 text

Feature: The whole system Scenario: Everything just works Given the system exists When I use it Then it works, perfectly

Slide 49

Slide 49 text

Whose domain is it anyway?

Slide 50

Slide 50 text

Solutions • Feedback • Feedback • Feedback

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Relish features • Full text search • Private projects • Editorial: • Markdown pages • Navigation / ToC ordering • Push from command-line

Slide 53

Slide 53 text

So... • Strive for documentation, not tests • Write scenarios collaboratively • Banish incidental details!

Slide 54

Slide 54 text

Thanks

Slide 55

Slide 55 text

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://relishapp.com • http://mattwynne.net • The Mythical Man-Month, Fred Brooks • The Goal, Eli Goldratt • @mattwynne