SlideShare a Scribd company logo
1 of 55
Growing software
from examples
Seb	
  Rose,	
  Claysnow	
  Limited
Twi$er:	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  @sebrose
Blog:	
  	
   	
   www.claysnow.co.uk
E-­‐mail:	
   	
   seb@claysnow.co.uk
Test Driven
Development
Acceptance Test
Driven Development
Behaviour DrivenDevelopment
Domain Driven
DesignSpecification by Example
Example Driven
Development
CustomerTest
?
Heavily influenced by GOOS book:
Pattern Generally good for Generally bad for
Given/When/
Then
Tests that require
•a lot of setup OR
•easily forgotten setup
Tests that have a non-obvious trigger
Tests with few expected outputs
• Tests that have unimportant/
simple/obvious preconditions
• Tests where there are multiple
different inputs and multiple
different outputs
• Tests where a single Given/
When/Then only describes one
of numerous very similar test
scenarios
•
Specification By
Example -
Conceptual or
Concrete
Tests that have numerous:
Inputs that affect output behavior
Outputs/expected behaviors
Tests where it’s important to test a lot
of different data scenarios
Tests where the trigger event is
somewhat obvious
Any test where it seems like a table
would be useful to:
describe the test better, or
help explore all of the possible
inputs and outputs for a test.
• Simple tests
• Tests that are more about
verifying simple UI behavior
For instance – “Test that an
error message is displayed when
the user enters an incorrect
password.”
• Test where there is really only
one input or precondition
http://www.scrumcrazy.com/file/view/ScrumCrazy.com_StoryTestingPatternsSummary3.pdf/391066838/ScrumCrazy.com_StoryTestingPatternsSummary3.pdf
They’re called different things
The difference is that one is called Behaviour
Driven Development – and some people find that
wording useful – and one (or two) is called
(Acceptance) Test Driven Development – and
some people find that wording useful in a
different way.
And that’s it.
Liz Keogh, 2011
http://lizkeogh.com/2011/06/27/atdd-vs-bdd-and-a-potted-history-of-some-related-stuff/
Outside-in
http://bddkickstart.com
http://exampler.com
Understandable
Desirable properties
Granular
Necessary
Maintainable
Reliable
Understandable
http://plus.maths.org/latestnews/sep-dec08/proof/proof.jpg
Maintainable
Necessary
Granular
Reliable
Work collaboratively
Create a ubiquitous language.
Use examples to discover the domain.
Decompose ruthlessly.
Online subscriptions
In order to make getting the magazine simpler
visitors should be able to
subscribe online with a VISA card
User / Stakeholder Story
VISA subscriptions
In order to increase subscriptions
visitors should be able to
subscribe online with a VISA card
Acceptance Criteria
•Must support VISA
•Does not need to support MasterCard, Switch
•...
•Customers should be prevented from entering an
invalid credit card number
• ...
Credit Card Processing
Acceptance criteria:
Really? So tell me...
"Customers should be prevented from
entering an invalid credit card number"
• What exactly makes someone's
credit card number invalid?
• Can they use spaces?
• Should we checksum the digits?
• How do we feed back that the details
are invalid?
http://www.userdrivendev.com/p/user-language-inside-source-code.html
http://commitment-thebook.com
Remember your audience
Who should be able to read the examples?
Keep things clear.
What is their interest in them?
Don’t hide the context
	 [Test]
	 public void asterisk_should_format_to_emphasis()
	 {
String expected = "This is <em>em</em> text";
String actual = f.Format("This is *em* text");
	 	 Assert.AreEqual(expected, actual);
	 }
Don’t hide necessary context
Scenario: Increased delivery charges for zip code
Given my delivery zip code is in Alaska
When I go to the checkout
Then I will have to pay the higher delivery charges
Don’t hide important data
	 @Test
	 public void smoker_requires_manual_referral()
	 {
Referral referral = underwriting.process(smoker);
Assert.assertEquals(Referral.Manual, referral);
	 }
Make data explicit
	 @Test
	 public void smoker_requires_manual_referral()
	 {
Customer customer = new Customer(“Joe”, “Smith”,
“12/12/1980”, “Accountant”, “$300,000”, “Yes”,
“No”);
Referral referral = underwriting.process(customer);
Assert.assertEquals(Referral.Manual, referral);
	 }
Emphasise interesting details
	 @Test
	 public void smoker_requires_manual_referral()
	 {
CustomerBuilder builder = new CustomerBuilder();
Customer customer = builder
.withSmokerFlag()
.build();
Referral referral = underwriting.process(customer);
Assert.assertEquals(Referral.Manual, referral);
	 }
Declarative - makes a statement (.)
Prefer declarative examples
Exclamatory - shows excitement (!)
Interrogative - asks a question (?)
Imperative - makes a command (.)
Imperative vs Declarative Style
Feature: Sign up
Scenario: New user redirected to their own page
Given I am not logged in
And I visit the homepage
And I follow "Sign up"
And I fill in "Username" with "Seb"
And I fill in "Password" with "password"
And I fill in "Confirm password" with "password"
When I press "Sign up"
Then I should be on my feeds page
And I should see "Hello, Seb"
Imperative vs Declarative Style
Feature: Sign up
Scenario: New user redirected to their own page
When I sign up for a new account
Then I should be taken to my feeds page
And I should see a greeting message
Imperative vs Declarative Style
Feature: The entire system
This feature illustrates what can happen when you
take the declarative style too far.
Scenario: It works
When I use the system
Then it should work perfectly
Avoid workflow style
Every journey is made from single steps.
Workflows are more brittle.
A few workflows go a long way.
https://www.ibm.com/developerworks/library/j-aopwork11/TestingPyramid.jpg
Exploratory
and
manual
Workflow style
Scenario: Happy path for registration and purchase
Given I am on the homepage
And I register for an account in Alaska
And I go to the most popular item page
And I add the most popular item to my basket
And I go to checkout
And I select my delivery address
And I give valid payment details
When I confirm acceptance of terms and conditions
Then my purchase will be confirmed
Workflow style leads to repetition
Scenario: Correct postage price for Alaska
Given I am on the homepage
And I register for an account in “Alaska”
And I go to the most popular item page
And I add the most popular item to my basket
And I go to checkout
When I select delivery to my home address
Then I have to pay the higher delivery charge
Focus on a single action
Scenario: Correct postage price for Alaska
Given I am on the checkout page
When I select delivery to “Alaska”
Then I have to pay the higher delivery charge
Consider costs and benefits
Remove unnecessary examples
Exercise the thinnest slice possible
Automate when viable
Cost
Risk
Manual
Automate
Verify dependencies
“Don’t mock what you don’t own” JoeWalnes
Treat 2nd party code same as 3rd party.
Contract and collaboration tests.
• A stub in a collaboration test must
correspond to an expected result in a
contract test
• An expectation in a collaboration test must
correspond to an action in a contract test
J.B. Rainsberger, GOOS mailing list 15 March 2012
Contract and collaboration tests
Don’t let example dictate
mechanism
Visibility depends on interest not layer.
Remember the intended audience.
Acceptance tests not always end-to-end.
http://claysnow.co.uk/?p=175315341
Make technical tests visible
Scenario: High Risk rates for Test Pilots
Given an applicant with occupation “Test Pilot”
When the underwriting engine is invoked
Then we will use the “High Risk” rates table
Scenario: Applicant with high risk occupation
Given a standard, single-life, male applicant
But with a high risk occupation
When the application is processed
Then it will be referred for manual underwriting
Is this end to end?
@domain_model
@stubbed_persistence
Categorise in multiple dimensions
Faster feedback is better.
Other dimensions are also useful.
Take advantage of partitioning.
Examples are documentation
Requirements.
Living documentation.
Automated regression tests.
https://www.relishapp.com/GDS/whitehall
Nomenclature
Test
Example
Specification
http://www.slideshare.net/ehendrickson/the-thinking-tester-evolved
http://www.slideshare.net/ehendrickson/the-thinking-tester-evolved
Nomenclature
Test
Example
Specification
Check
What’s in a name?
“... it doesn't take much to see that
the problems of three little people
don't amount to a hill of beans in this
crazy world.”
Humphrey Bogart “Casablanca”
Summary
Example-based methods are very similar.
Minor variations by target audience.
Skills are transferable.
The naming genie is out of the bottle.
Collaboration is key.
Seb	
  Rose
Twi$er:	
  	
   @sebrose
Blog:	
  	
   	
   www.claysnow.co.uk
E-­‐mail:	
   	
  	
  	
  	
  	
  seb@claysnow.co.uk

More Related Content

Similar to Growing software from examples

Testable Requirements
Testable Requirements Testable Requirements
Testable Requirements Bharti Rupani
 
Acceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles BradleyAcceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles BradleySynerzip
 
Growing software from examples
Growing software from examplesGrowing software from examples
Growing software from examplesSeb Rose
 
Panning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile CoachPanning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile CoachSynerzip
 
Implement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlowImplement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlowTechWell
 
Modeling Requirements Using Examples
Modeling Requirements Using ExamplesModeling Requirements Using Examples
Modeling Requirements Using ExamplesExcella
 
The Best A/B Test Idea You Haven’t Thought Of
The Best A/B Test Idea You Haven’t Thought OfThe Best A/B Test Idea You Haven’t Thought Of
The Best A/B Test Idea You Haven’t Thought OfKissmetrics on SlideShare
 
Using Stories to Test Requirements and Systems
Using Stories to Test Requirements and SystemsUsing Stories to Test Requirements and Systems
Using Stories to Test Requirements and SystemsPaul Gerrard
 
Living with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-OnceLiving with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-OnceDaniel Wellman
 
Writing Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance CriteriaWriting Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance CriteriaHoa Le
 
Journey to Testable Requirements
Journey to Testable RequirementsJourney to Testable Requirements
Journey to Testable RequirementsBharti Rupani
 
Optimizely Developer Showcase
Optimizely Developer ShowcaseOptimizely Developer Showcase
Optimizely Developer ShowcaseOptimizely
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2Rosie Sherry
 
Xamariners - BDD + Mobile
Xamariners - BDD + MobileXamariners - BDD + Mobile
Xamariners - BDD + MobileXamariners
 
Why BDD is our BFF
Why BDD is our BFFWhy BDD is our BFF
Why BDD is our BFFmdaubs
 
Stop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo SimulationStop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo SimulationSam McAfee
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...John Ferguson Smart Limited
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingViget Labs
 

Similar to Growing software from examples (20)

Testable requirements
Testable requirementsTestable requirements
Testable requirements
 
Testable Requirements
Testable Requirements Testable Requirements
Testable Requirements
 
Acceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles BradleyAcceptance And Story Testing Patterns - By Charles Bradley
Acceptance And Story Testing Patterns - By Charles Bradley
 
Growing software from examples
Growing software from examplesGrowing software from examples
Growing software from examples
 
Panning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile CoachPanning for User Story Gold - by Damon Poole, Agile Coach
Panning for User Story Gold - by Damon Poole, Agile Coach
 
Implement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlowImplement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlow
 
Modeling Requirements Using Examples
Modeling Requirements Using ExamplesModeling Requirements Using Examples
Modeling Requirements Using Examples
 
The Best A/B Test Idea You Haven’t Thought Of
The Best A/B Test Idea You Haven’t Thought OfThe Best A/B Test Idea You Haven’t Thought Of
The Best A/B Test Idea You Haven’t Thought Of
 
Using Stories to Test Requirements and Systems
Using Stories to Test Requirements and SystemsUsing Stories to Test Requirements and Systems
Using Stories to Test Requirements and Systems
 
Living with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-OnceLiving with Acceptance Tests: Beyond Write-Once
Living with Acceptance Tests: Beyond Write-Once
 
Writing Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance CriteriaWriting Test Cases From User Stories And Acceptance Criteria
Writing Test Cases From User Stories And Acceptance Criteria
 
Journey to Testable Requirements
Journey to Testable RequirementsJourney to Testable Requirements
Journey to Testable Requirements
 
Optimizely Developer Showcase
Optimizely Developer ShowcaseOptimizely Developer Showcase
Optimizely Developer Showcase
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
 
Xamariners - BDD + Mobile
Xamariners - BDD + MobileXamariners - BDD + Mobile
Xamariners - BDD + Mobile
 
Why BDD is our BFF
Why BDD is our BFFWhy BDD is our BFF
Why BDD is our BFF
 
Double Loop
Double LoopDouble Loop
Double Loop
 
Stop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo SimulationStop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo Simulation
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
 

More from Seb Rose

Software contracts - Global Enterprise Agile 2023.pdf
Software contracts - Global Enterprise Agile 2023.pdfSoftware contracts - Global Enterprise Agile 2023.pdf
Software contracts - Global Enterprise Agile 2023.pdfSeb Rose
 
Micro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsMicro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsSeb Rose
 
DevSecOps - Agile Get-Together 2022.pdf
DevSecOps - Agile Get-Together 2022.pdfDevSecOps - Agile Get-Together 2022.pdf
DevSecOps - Agile Get-Together 2022.pdfSeb Rose
 
Contract testing - Sealights 2022.pdf
Contract testing - Sealights 2022.pdfContract testing - Sealights 2022.pdf
Contract testing - Sealights 2022.pdfSeb Rose
 
Example mapping - slice any story into testable examples - SoCraTes 2022.pdf
Example mapping - slice any story into testable examples - SoCraTes 2022.pdfExample mapping - slice any story into testable examples - SoCraTes 2022.pdf
Example mapping - slice any story into testable examples - SoCraTes 2022.pdfSeb Rose
 
Software testing - learning to walk again (expoQA22)
Software testing - learning to walk again (expoQA22)Software testing - learning to walk again (expoQA22)
Software testing - learning to walk again (expoQA22)Seb Rose
 
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021Seb Rose
 
A brief history of requirements - Unicom 2022
A brief history of requirements  - Unicom 2022A brief history of requirements  - Unicom 2022
A brief history of requirements - Unicom 2022Seb Rose
 
Example mapping (with builds) - ProductWorld 2022
Example mapping (with builds)  - ProductWorld 2022Example mapping (with builds)  - ProductWorld 2022
Example mapping (with builds) - ProductWorld 2022Seb Rose
 
Example mapping - ProductWorld 2022
Example mapping - ProductWorld 2022Example mapping - ProductWorld 2022
Example mapping - ProductWorld 2022Seb Rose
 
No code, low code, machine code QA ATL 2021
No code, low code, machine code   QA ATL 2021No code, low code, machine code   QA ATL 2021
No code, low code, machine code QA ATL 2021Seb Rose
 
No code, low code, machine code QA ATL 2021
No code, low code, machine code   QA ATL 2021No code, low code, machine code   QA ATL 2021
No code, low code, machine code QA ATL 2021Seb Rose
 
No code, low code, machine code - Unicom 2021
No code, low code, machine code -  Unicom 2021No code, low code, machine code -  Unicom 2021
No code, low code, machine code - Unicom 2021Seb Rose
 
BDD: from soup to nuts - The Future of Work Scotland 2021
BDD: from soup to nuts  - The Future of Work Scotland 2021BDD: from soup to nuts  - The Future of Work Scotland 2021
BDD: from soup to nuts - The Future of Work Scotland 2021Seb Rose
 
Contrasting test automation and BDD - 2020
Contrasting test automation and BDD - 2020Contrasting test automation and BDD - 2020
Contrasting test automation and BDD - 2020Seb Rose
 
Are BDD and test automation the same thing? Automation Guild 2021
Are BDD and test automation the same thing?   Automation Guild 2021Are BDD and test automation the same thing?   Automation Guild 2021
Are BDD and test automation the same thing? Automation Guild 2021Seb Rose
 
"Our BDDs are broken!" Lean Agile Exchange 2020
"Our BDDs are broken!"   Lean Agile Exchange 2020"Our BDDs are broken!"   Lean Agile Exchange 2020
"Our BDDs are broken!" Lean Agile Exchange 2020Seb Rose
 
User stories: from good intentions to bad advice - Agile Scotland 2019
User stories: from good intentions to bad advice - Agile Scotland 2019User stories: from good intentions to bad advice - Agile Scotland 2019
User stories: from good intentions to bad advice - Agile Scotland 2019Seb Rose
 
User stories: from good intentions to bad advice - Lean Agile Scotland 2019
User stories: from good intentions to bad advice - Lean Agile Scotland 2019User stories: from good intentions to bad advice - Lean Agile Scotland 2019
User stories: from good intentions to bad advice - Lean Agile Scotland 2019Seb Rose
 
Software contracts or: how I learned to stop worrying and love releasing. Agi...
Software contracts or: how I learned to stop worrying and love releasing. Agi...Software contracts or: how I learned to stop worrying and love releasing. Agi...
Software contracts or: how I learned to stop worrying and love releasing. Agi...Seb Rose
 

More from Seb Rose (20)

Software contracts - Global Enterprise Agile 2023.pdf
Software contracts - Global Enterprise Agile 2023.pdfSoftware contracts - Global Enterprise Agile 2023.pdf
Software contracts - Global Enterprise Agile 2023.pdf
 
Micro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsMicro-service delivery - without the pitfalls
Micro-service delivery - without the pitfalls
 
DevSecOps - Agile Get-Together 2022.pdf
DevSecOps - Agile Get-Together 2022.pdfDevSecOps - Agile Get-Together 2022.pdf
DevSecOps - Agile Get-Together 2022.pdf
 
Contract testing - Sealights 2022.pdf
Contract testing - Sealights 2022.pdfContract testing - Sealights 2022.pdf
Contract testing - Sealights 2022.pdf
 
Example mapping - slice any story into testable examples - SoCraTes 2022.pdf
Example mapping - slice any story into testable examples - SoCraTes 2022.pdfExample mapping - slice any story into testable examples - SoCraTes 2022.pdf
Example mapping - slice any story into testable examples - SoCraTes 2022.pdf
 
Software testing - learning to walk again (expoQA22)
Software testing - learning to walk again (expoQA22)Software testing - learning to walk again (expoQA22)
Software testing - learning to walk again (expoQA22)
 
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
 
A brief history of requirements - Unicom 2022
A brief history of requirements  - Unicom 2022A brief history of requirements  - Unicom 2022
A brief history of requirements - Unicom 2022
 
Example mapping (with builds) - ProductWorld 2022
Example mapping (with builds)  - ProductWorld 2022Example mapping (with builds)  - ProductWorld 2022
Example mapping (with builds) - ProductWorld 2022
 
Example mapping - ProductWorld 2022
Example mapping - ProductWorld 2022Example mapping - ProductWorld 2022
Example mapping - ProductWorld 2022
 
No code, low code, machine code QA ATL 2021
No code, low code, machine code   QA ATL 2021No code, low code, machine code   QA ATL 2021
No code, low code, machine code QA ATL 2021
 
No code, low code, machine code QA ATL 2021
No code, low code, machine code   QA ATL 2021No code, low code, machine code   QA ATL 2021
No code, low code, machine code QA ATL 2021
 
No code, low code, machine code - Unicom 2021
No code, low code, machine code -  Unicom 2021No code, low code, machine code -  Unicom 2021
No code, low code, machine code - Unicom 2021
 
BDD: from soup to nuts - The Future of Work Scotland 2021
BDD: from soup to nuts  - The Future of Work Scotland 2021BDD: from soup to nuts  - The Future of Work Scotland 2021
BDD: from soup to nuts - The Future of Work Scotland 2021
 
Contrasting test automation and BDD - 2020
Contrasting test automation and BDD - 2020Contrasting test automation and BDD - 2020
Contrasting test automation and BDD - 2020
 
Are BDD and test automation the same thing? Automation Guild 2021
Are BDD and test automation the same thing?   Automation Guild 2021Are BDD and test automation the same thing?   Automation Guild 2021
Are BDD and test automation the same thing? Automation Guild 2021
 
"Our BDDs are broken!" Lean Agile Exchange 2020
"Our BDDs are broken!"   Lean Agile Exchange 2020"Our BDDs are broken!"   Lean Agile Exchange 2020
"Our BDDs are broken!" Lean Agile Exchange 2020
 
User stories: from good intentions to bad advice - Agile Scotland 2019
User stories: from good intentions to bad advice - Agile Scotland 2019User stories: from good intentions to bad advice - Agile Scotland 2019
User stories: from good intentions to bad advice - Agile Scotland 2019
 
User stories: from good intentions to bad advice - Lean Agile Scotland 2019
User stories: from good intentions to bad advice - Lean Agile Scotland 2019User stories: from good intentions to bad advice - Lean Agile Scotland 2019
User stories: from good intentions to bad advice - Lean Agile Scotland 2019
 
Software contracts or: how I learned to stop worrying and love releasing. Agi...
Software contracts or: how I learned to stop worrying and love releasing. Agi...Software contracts or: how I learned to stop worrying and love releasing. Agi...
Software contracts or: how I learned to stop worrying and love releasing. Agi...
 

Growing software from examples

  • 1. Growing software from examples Seb  Rose,  Claysnow  Limited Twi$er:                          @sebrose Blog:       www.claysnow.co.uk E-­‐mail:     seb@claysnow.co.uk
  • 2. Test Driven Development Acceptance Test Driven Development Behaviour DrivenDevelopment Domain Driven DesignSpecification by Example Example Driven Development CustomerTest ?
  • 4.
  • 5.
  • 6. Pattern Generally good for Generally bad for Given/When/ Then Tests that require •a lot of setup OR •easily forgotten setup Tests that have a non-obvious trigger Tests with few expected outputs • Tests that have unimportant/ simple/obvious preconditions • Tests where there are multiple different inputs and multiple different outputs • Tests where a single Given/ When/Then only describes one of numerous very similar test scenarios • Specification By Example - Conceptual or Concrete Tests that have numerous: Inputs that affect output behavior Outputs/expected behaviors Tests where it’s important to test a lot of different data scenarios Tests where the trigger event is somewhat obvious Any test where it seems like a table would be useful to: describe the test better, or help explore all of the possible inputs and outputs for a test. • Simple tests • Tests that are more about verifying simple UI behavior For instance – “Test that an error message is displayed when the user enters an incorrect password.” • Test where there is really only one input or precondition http://www.scrumcrazy.com/file/view/ScrumCrazy.com_StoryTestingPatternsSummary3.pdf/391066838/ScrumCrazy.com_StoryTestingPatternsSummary3.pdf
  • 7. They’re called different things The difference is that one is called Behaviour Driven Development – and some people find that wording useful – and one (or two) is called (Acceptance) Test Driven Development – and some people find that wording useful in a different way. And that’s it. Liz Keogh, 2011 http://lizkeogh.com/2011/06/27/atdd-vs-bdd-and-a-potted-history-of-some-related-stuff/
  • 16. Work collaboratively Create a ubiquitous language. Use examples to discover the domain. Decompose ruthlessly.
  • 17. Online subscriptions In order to make getting the magazine simpler visitors should be able to subscribe online with a VISA card User / Stakeholder Story
  • 18. VISA subscriptions In order to increase subscriptions visitors should be able to subscribe online with a VISA card Acceptance Criteria •Must support VISA •Does not need to support MasterCard, Switch •... •Customers should be prevented from entering an invalid credit card number • ... Credit Card Processing Acceptance criteria:
  • 19. Really? So tell me... "Customers should be prevented from entering an invalid credit card number" • What exactly makes someone's credit card number invalid? • Can they use spaces? • Should we checksum the digits? • How do we feed back that the details are invalid?
  • 22. Remember your audience Who should be able to read the examples? Keep things clear. What is their interest in them?
  • 23. Don’t hide the context [Test] public void asterisk_should_format_to_emphasis() { String expected = "This is <em>em</em> text"; String actual = f.Format("This is *em* text"); Assert.AreEqual(expected, actual); }
  • 24. Don’t hide necessary context Scenario: Increased delivery charges for zip code Given my delivery zip code is in Alaska When I go to the checkout Then I will have to pay the higher delivery charges
  • 25. Don’t hide important data @Test public void smoker_requires_manual_referral() { Referral referral = underwriting.process(smoker); Assert.assertEquals(Referral.Manual, referral); }
  • 26. Make data explicit @Test public void smoker_requires_manual_referral() { Customer customer = new Customer(“Joe”, “Smith”, “12/12/1980”, “Accountant”, “$300,000”, “Yes”, “No”); Referral referral = underwriting.process(customer); Assert.assertEquals(Referral.Manual, referral); }
  • 27. Emphasise interesting details @Test public void smoker_requires_manual_referral() { CustomerBuilder builder = new CustomerBuilder(); Customer customer = builder .withSmokerFlag() .build(); Referral referral = underwriting.process(customer); Assert.assertEquals(Referral.Manual, referral); }
  • 28. Declarative - makes a statement (.) Prefer declarative examples Exclamatory - shows excitement (!) Interrogative - asks a question (?) Imperative - makes a command (.)
  • 29. Imperative vs Declarative Style Feature: Sign up Scenario: New user redirected to their own page Given I am not logged in And I visit the homepage And I follow "Sign up" And I fill in "Username" with "Seb" And I fill in "Password" with "password" And I fill in "Confirm password" with "password" When I press "Sign up" Then I should be on my feeds page And I should see "Hello, Seb"
  • 30. Imperative vs Declarative Style Feature: Sign up Scenario: New user redirected to their own page When I sign up for a new account Then I should be taken to my feeds page And I should see a greeting message
  • 31. Imperative vs Declarative Style Feature: The entire system This feature illustrates what can happen when you take the declarative style too far. Scenario: It works When I use the system Then it should work perfectly
  • 32. Avoid workflow style Every journey is made from single steps. Workflows are more brittle. A few workflows go a long way.
  • 34. Workflow style Scenario: Happy path for registration and purchase Given I am on the homepage And I register for an account in Alaska And I go to the most popular item page And I add the most popular item to my basket And I go to checkout And I select my delivery address And I give valid payment details When I confirm acceptance of terms and conditions Then my purchase will be confirmed
  • 35. Workflow style leads to repetition Scenario: Correct postage price for Alaska Given I am on the homepage And I register for an account in “Alaska” And I go to the most popular item page And I add the most popular item to my basket And I go to checkout When I select delivery to my home address Then I have to pay the higher delivery charge
  • 36. Focus on a single action Scenario: Correct postage price for Alaska Given I am on the checkout page When I select delivery to “Alaska” Then I have to pay the higher delivery charge
  • 37. Consider costs and benefits Remove unnecessary examples Exercise the thinnest slice possible Automate when viable
  • 39.
  • 40. Verify dependencies “Don’t mock what you don’t own” JoeWalnes Treat 2nd party code same as 3rd party. Contract and collaboration tests.
  • 41. • A stub in a collaboration test must correspond to an expected result in a contract test • An expectation in a collaboration test must correspond to an action in a contract test J.B. Rainsberger, GOOS mailing list 15 March 2012 Contract and collaboration tests
  • 42. Don’t let example dictate mechanism Visibility depends on interest not layer. Remember the intended audience. Acceptance tests not always end-to-end.
  • 44. Make technical tests visible Scenario: High Risk rates for Test Pilots Given an applicant with occupation “Test Pilot” When the underwriting engine is invoked Then we will use the “High Risk” rates table
  • 45. Scenario: Applicant with high risk occupation Given a standard, single-life, male applicant But with a high risk occupation When the application is processed Then it will be referred for manual underwriting Is this end to end? @domain_model @stubbed_persistence
  • 46. Categorise in multiple dimensions Faster feedback is better. Other dimensions are also useful. Take advantage of partitioning.
  • 47. Examples are documentation Requirements. Living documentation. Automated regression tests.
  • 53. What’s in a name? “... it doesn't take much to see that the problems of three little people don't amount to a hill of beans in this crazy world.” Humphrey Bogart “Casablanca”
  • 54. Summary Example-based methods are very similar. Minor variations by target audience. Skills are transferable. The naming genie is out of the bottle. Collaboration is key.
  • 55. Seb  Rose Twi$er:     @sebrose Blog:       www.claysnow.co.uk E-­‐mail:            seb@claysnow.co.uk