SlideShare a Scribd company logo
1 of 34
TDD & BDD
   Testing in F#
Phil Trelford and Chis Marinos
Progressive F# Tutorials 2011
Organization

   REPL
       REPL Task
   TDD
     Introduction
     Unit Testing Tasks

   BDD
     Introduction
     Acceptance Testing Tasks
Unit Testing Frameworks


   F# supports all major unit testing frameworks
     NUnit
     xUnit
     mbUnit
     MsTest
    …
Fluent Interfaces


 FsUnit
 FsTest
 NaturalSpec
FsUnit

[<Test>]
let ``when player A wins the score should be 15-0`` () =
    [A]
    |> scoreGame
    |> should be (equal (Points(Fifteen,Zero)))
Agile Manifesto
   Individuals and interactions over
    processes and tools

   Working software over
    comprehensive documentation

   Customer collaboration over
    contract negotiation

   Responding to change over
    following a plan
Collaboration


     Developer   Customers




                 Business
      Testers
                  Analyst
User Stories
Acceptance Tests


Refunded items should be returned to stock
 Given a customer buys a black jumper
 And I have 3 black jumpers left in stock
 When he returns the black jumper for a
  refund
 Then I should have 4 black jumpers in stock
Test Driven Development
(TDD)
Benefits
 Facilitates change
       Refactoring
       Regression Testing
   Documentation
       API
       Living Documentation
   Design
       Classes, Methods
       Behaviour
Unit Testing


“A good unit test needs both to illustrate and
  define the behavioural contract of the unit
  in question. Behaviour is more than just
  individual methods…” – Kevlin Henney
Behaviour Driven Development
(BDD)
“Is an agile software development technique that
   encourages collaboration between
 Developers
 QA
 Business Participants
   in a software project.”

“It extends TDD by writing test cases in a
    natural language that non-programmers can read.”
Behaviour Driven
Development (BDD)
Benefits
 Facilitates Change
       Refactoring
       Regression
       Rewriting
   Documentation
       Behaviour
       Living Documentation
       Domain Language
   Defines Done
       When all tests pass
Team Workshops
BA + Developer + QA
Testers find holes
BDD Frameworks
External DSL    Internal DSL

   Cuke4Nuke      MSpec
   NBehave        NaturalSpec
   StorEvil       NSpec
   SpecFlow       SpecsFor
   TickSpec       StoryQ
Declarations
Gherkin                          NaturalSpec
Given I input 5                  [<Scenario>] let
When calculating the factorial   ``When calculating factorial of 5 it
Then the result is 120           should equal 120``() =
                                 Given 5
                                 |> When calculating factorial
                                 |> It should equal 120
                                 |> Verify
First Steps in BDD on .Net

            • Shell
 StorEvil
            • C# & F#
                                        Gherkin
                              NUnit


            • Visual Studio           Visual
 SpecFlow                             Studio
            • C#


                                      ?
            • F# & C#
    ?
            • VS & Shell
Look no hands
Look no hands
TickSpec
Demo
Task: BOGOF

   As a retailer I want to offer my customers buy
    one get one free promotions
Step away from the tools


“Start by having conversations, engaging both
testers and business stakeholders
If you can’t have those conversations, stop.
You can’t do BDD” – Liz Keogh
What makes a good feature file
   About the business domain
   In domain language
   Specification – not a script
   Easy to understand
   Focused on a single thing
   Precise and testable
   Self-explanatory
   Consistent
   Easy to access
BDD Patterns: Tables
Scenario: Winning positions
      Given a board layout:
            | 1 | 2 | 3 |
            | O | O | X |
            | O |   |   |
            | X |   | X |
      When I mark X at middle right
      Then I win
What makes a bad feature file

 Long sentences
 Repetitious sentences
 Repetitive scenarios


 A never ending story
 Commentary
 And another thing
BDD Patterns: Examples
Scenario: Winning positions
       Given a board layout:
              | 1 | 2 | 3 |
              | O | O | X |
              | O |   |   |
              | X |   | X |
       When I mark X at <row> <col>
       Then I win

Examples:
       | row      |   col      |
       | middle   |   right    |
       | middle   |   middle   |
       | bottom   |   middle   |
Terry's Chocolate Oranges sold
for just 29p each
Two simultaneous
promotions:
 three-for-£5 offer
 buy-one-get-one-free


Equals:
 £2.75 product
 Sells for 29p
Yum!
BDD Books
Lifetime BDD Awards


           @tastapod

            @lunivore

           @gojkoadzic
Q&A

More Related Content

Similar to TDD & BDD in F# at Progressive F# Tutorials 2011

Behavior Driven Development: An Overview
Behavior Driven Development:  An OverviewBehavior Driven Development:  An Overview
Behavior Driven Development: An Overview
bmaynard_at_litle
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
Marakana Inc.
 

Similar to TDD & BDD in F# at Progressive F# Tutorials 2011 (20)

BDD with F# at DDDBelfast
BDD with F# at DDDBelfastBDD with F# at DDDBelfast
BDD with F# at DDDBelfast
 
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
NDC 2011 - SpecFlow: Pragmatic BDD for .NETNDC 2011 - SpecFlow: Pragmatic BDD for .NET
NDC 2011 - SpecFlow: Pragmatic BDD for .NET
 
Java Zone 2017 - Build the right system
Java Zone 2017  - Build the right systemJava Zone 2017  - Build the right system
Java Zone 2017 - Build the right system
 
Spec(ing) Out Your Workflow with SpecFlow
Spec(ing) Out Your Workflow with SpecFlowSpec(ing) Out Your Workflow with SpecFlow
Spec(ing) Out Your Workflow with SpecFlow
 
Agile Software Development in Practice - A Developer Perspective
Agile Software Development in Practice - A Developer PerspectiveAgile Software Development in Practice - A Developer Perspective
Agile Software Development in Practice - A Developer Perspective
 
Behavior Driven Development: An Overview
Behavior Driven Development:  An OverviewBehavior Driven Development:  An Overview
Behavior Driven Development: An Overview
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Bdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propriBdd - L'arte di non farsi i fatti propri
Bdd - L'arte di non farsi i fatti propri
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
 
Emily Bache - Readable, Executable Requirements: Hands-On - EuroSTAR 2013
Emily Bache - Readable, Executable Requirements: Hands-On - EuroSTAR 2013Emily Bache - Readable, Executable Requirements: Hands-On - EuroSTAR 2013
Emily Bache - Readable, Executable Requirements: Hands-On - EuroSTAR 2013
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Prashant technical practices-tdd for xebia event
Prashant   technical practices-tdd for xebia eventPrashant   technical practices-tdd for xebia event
Prashant technical practices-tdd for xebia event
 
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 

More from Phillip Trelford

F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015
Phillip Trelford
 
F# for C# devs - Leeds Sharp 2015
F# for C# devs -  Leeds Sharp 2015F# for C# devs -  Leeds Sharp 2015
F# for C# devs - Leeds Sharp 2015
Phillip Trelford
 

More from Phillip Trelford (20)

How to be a rock star developer
How to be a rock star developerHow to be a rock star developer
How to be a rock star developer
 
Mobile F#un
Mobile F#unMobile F#un
Mobile F#un
 
F# eXchange Keynote 2016
F# eXchange Keynote 2016F# eXchange Keynote 2016
F# eXchange Keynote 2016
 
FSharp eye for the Haskell guy - London 2015
FSharp eye for the Haskell guy - London 2015FSharp eye for the Haskell guy - London 2015
FSharp eye for the Haskell guy - London 2015
 
Beyond lists - Copenhagen 2015
Beyond lists - Copenhagen 2015Beyond lists - Copenhagen 2015
Beyond lists - Copenhagen 2015
 
F# for C# devs - Copenhagen .Net 2015
F# for C# devs - Copenhagen .Net 2015F# for C# devs - Copenhagen .Net 2015
F# for C# devs - Copenhagen .Net 2015
 
Generative Art - Functional Vilnius 2015
Generative Art - Functional Vilnius 2015Generative Art - Functional Vilnius 2015
Generative Art - Functional Vilnius 2015
 
24 hours later - FSharp Gotham 2015
24 hours later - FSharp Gotham  201524 hours later - FSharp Gotham  2015
24 hours later - FSharp Gotham 2015
 
Building cross platform games with Xamarin - Birmingham 2015
Building cross platform games with Xamarin - Birmingham 2015Building cross platform games with Xamarin - Birmingham 2015
Building cross platform games with Xamarin - Birmingham 2015
 
Beyond Lists - Functional Kats Conf Dublin 2015
Beyond Lists - Functional Kats Conf Dublin 2015Beyond Lists - Functional Kats Conf Dublin 2015
Beyond Lists - Functional Kats Conf Dublin 2015
 
FSharp On The Desktop - Birmingham FP 2015
FSharp On The Desktop - Birmingham FP 2015FSharp On The Desktop - Birmingham FP 2015
FSharp On The Desktop - Birmingham FP 2015
 
Ready, steady, cross platform games - ProgNet 2015
Ready, steady, cross platform games - ProgNet 2015Ready, steady, cross platform games - ProgNet 2015
Ready, steady, cross platform games - ProgNet 2015
 
F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015F# for C# devs - NDC Oslo 2015
F# for C# devs - NDC Oslo 2015
 
F# for C# devs - Leeds Sharp 2015
F# for C# devs -  Leeds Sharp 2015F# for C# devs -  Leeds Sharp 2015
F# for C# devs - Leeds Sharp 2015
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
24 Hours Later - NCrafts Paris 2015
24 Hours Later - NCrafts Paris 201524 Hours Later - NCrafts Paris 2015
24 Hours Later - NCrafts Paris 2015
 
Real World F# - SDD 2015
Real World F# -  SDD 2015Real World F# -  SDD 2015
Real World F# - SDD 2015
 
F# for C# devs - SDD 2015
F# for C# devs - SDD 2015F# for C# devs - SDD 2015
F# for C# devs - SDD 2015
 
Machine learning from disaster - GL.Net 2015
Machine learning from disaster  - GL.Net 2015Machine learning from disaster  - GL.Net 2015
Machine learning from disaster - GL.Net 2015
 
F# for Trading - QuantLabs 2014
F# for Trading -  QuantLabs 2014F# for Trading -  QuantLabs 2014
F# for Trading - QuantLabs 2014
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

TDD & BDD in F# at Progressive F# Tutorials 2011

  • 1. TDD & BDD Testing in F# Phil Trelford and Chis Marinos Progressive F# Tutorials 2011
  • 2. Organization  REPL  REPL Task  TDD  Introduction  Unit Testing Tasks  BDD  Introduction  Acceptance Testing Tasks
  • 3. Unit Testing Frameworks  F# supports all major unit testing frameworks  NUnit  xUnit  mbUnit  MsTest …
  • 4. Fluent Interfaces  FsUnit  FsTest  NaturalSpec
  • 5. FsUnit [<Test>] let ``when player A wins the score should be 15-0`` () = [A] |> scoreGame |> should be (equal (Points(Fifteen,Zero)))
  • 6. Agile Manifesto  Individuals and interactions over processes and tools  Working software over comprehensive documentation  Customer collaboration over contract negotiation  Responding to change over following a plan
  • 7. Collaboration Developer Customers Business Testers Analyst
  • 9. Acceptance Tests Refunded items should be returned to stock  Given a customer buys a black jumper  And I have 3 black jumpers left in stock  When he returns the black jumper for a refund  Then I should have 4 black jumpers in stock
  • 10. Test Driven Development (TDD) Benefits  Facilitates change  Refactoring  Regression Testing  Documentation  API  Living Documentation  Design  Classes, Methods  Behaviour
  • 11. Unit Testing “A good unit test needs both to illustrate and define the behavioural contract of the unit in question. Behaviour is more than just individual methods…” – Kevlin Henney
  • 12. Behaviour Driven Development (BDD) “Is an agile software development technique that encourages collaboration between  Developers  QA  Business Participants in a software project.” “It extends TDD by writing test cases in a natural language that non-programmers can read.”
  • 13. Behaviour Driven Development (BDD) Benefits  Facilitates Change  Refactoring  Regression  Rewriting  Documentation  Behaviour  Living Documentation  Domain Language  Defines Done  When all tests pass
  • 17. BDD Frameworks External DSL Internal DSL  Cuke4Nuke  MSpec  NBehave  NaturalSpec  StorEvil  NSpec  SpecFlow  SpecsFor  TickSpec  StoryQ
  • 18. Declarations Gherkin NaturalSpec Given I input 5 [<Scenario>] let When calculating the factorial ``When calculating factorial of 5 it Then the result is 120 should equal 120``() = Given 5 |> When calculating factorial |> It should equal 120 |> Verify
  • 19. First Steps in BDD on .Net • Shell StorEvil • C# & F# Gherkin NUnit • Visual Studio Visual SpecFlow Studio • C# ? • F# & C# ? • VS & Shell
  • 23. Demo
  • 24. Task: BOGOF  As a retailer I want to offer my customers buy one get one free promotions
  • 25. Step away from the tools “Start by having conversations, engaging both testers and business stakeholders If you can’t have those conversations, stop. You can’t do BDD” – Liz Keogh
  • 26. What makes a good feature file  About the business domain  In domain language  Specification – not a script  Easy to understand  Focused on a single thing  Precise and testable  Self-explanatory  Consistent  Easy to access
  • 27. BDD Patterns: Tables Scenario: Winning positions Given a board layout: | 1 | 2 | 3 | | O | O | X | | O | | | | X | | X | When I mark X at middle right Then I win
  • 28. What makes a bad feature file  Long sentences  Repetitious sentences  Repetitive scenarios  A never ending story  Commentary  And another thing
  • 29. BDD Patterns: Examples Scenario: Winning positions Given a board layout: | 1 | 2 | 3 | | O | O | X | | O | | | | X | | X | When I mark X at <row> <col> Then I win Examples: | row | col | | middle | right | | middle | middle | | bottom | middle |
  • 30. Terry's Chocolate Oranges sold for just 29p each Two simultaneous promotions:  three-for-£5 offer  buy-one-get-one-free Equals:  £2.75 product  Sells for 29p
  • 31. Yum!
  • 33. Lifetime BDD Awards @tastapod @lunivore @gojkoadzic
  • 34. Q&A

Editor's Notes

  1. http://www.stickyminds.com/sitewide.asp?Function=edetail&amp;ObjectType=ART&amp;ObjectId=13833&amp;tth=DYN&amp;tt=siteemail&amp;iDyn=2Key part here is “A good unit test needs to define the behavioural contract”These kind of observations were what prompted Dan North into evolving TDD into BDD, which is what we will discuss next.
  2. This is a description of what BDD is and how it relates to TDD.
  3. BDD also known as Acceptance Test Driven Development etc.