tdd & bdd in f# at progressive f# tutorials 2011
DESCRIPTION
In this practical session we’ll start by implementing fluent unit tests in F# using FsUnit and NUnit. We’ll then break into teams and develop scenarios in English language to solve a real world scenario and then automate them with the TickSpec library. Video: http://skillsmatter.com/podcast/scala/tdd-and-bdd Tasks: http://trelford.com/progfsharp.zipTRANSCRIPT
![Page 1: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/1.jpg)
TDD & BDDTesting in F#
Phil Trelford and Chis Marinos
Progressive F# Tutorials 2011
![Page 2: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/2.jpg)
Organization
REPL REPL Task
TDD Introduction Unit Testing Tasks
BDD Introduction Acceptance Testing Tasks
![Page 3: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/3.jpg)
Unit Testing Frameworks
F# supports all major unit testing frameworks NUnit xUnit mbUnit MsTest …
![Page 4: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/4.jpg)
Fluent Interfaces
FsUnit FsTest NaturalSpec
![Page 5: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/5.jpg)
FsUnit
[<Test>]let ``when player A wins the score should be 15-0`` () = [A] |> scoreGame |> should be (equal (Points(Fifteen,Zero)))
![Page 6: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/6.jpg)
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
![Page 7: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/7.jpg)
Collaboration
Customers
Business AnalystTesters
Developer
![Page 8: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/8.jpg)
User Stories
![Page 9: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/9.jpg)
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
![Page 10: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/10.jpg)
Test Driven Development (TDD)Benefits Facilitates change
Refactoring Regression Testing
Documentation API Living Documentation
Design Classes, Methods Behaviour
![Page 11: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/11.jpg)
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
![Page 12: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/12.jpg)
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.”
![Page 13: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/13.jpg)
Behaviour Driven Development (BDD)Benefits Facilitates Change
Refactoring Regression Rewriting
Documentation Behaviour Living Documentation Domain Language
Defines Done When all tests pass
![Page 14: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/14.jpg)
Team Workshops
![Page 15: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/15.jpg)
BA + Developer + QA
![Page 16: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/16.jpg)
Testers find holes
![Page 17: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/17.jpg)
BDD Frameworks
External DSL
Cuke4Nuke NBehave StorEvil SpecFlow TickSpec
Internal DSL
MSpec NaturalSpec NSpec SpecsFor StoryQ
![Page 18: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/18.jpg)
Declarations
GherkinGiven I input 5
When calculating the factorial
Then the result is 120
NaturalSpec[<Scenario>] let
``When calculating factorial of 5 it should equal 120``() =
Given 5
|> When calculating factorial
|> It should equal 120
|> Verify
![Page 19: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/19.jpg)
First Steps in BDD on .Net
• Shell• C# & F#
StorEvil
• Visual Studio• C#
SpecFlow
• F# & C#• VS & Shell
?
?
Visual Studio
NUnitGherkin
![Page 20: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/20.jpg)
Look no hands
![Page 21: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/21.jpg)
Look no hands
![Page 22: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/22.jpg)
TickSpec
![Page 23: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/23.jpg)
Demo
![Page 24: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/24.jpg)
Task: BOGOF
As a retailer I want to offer my customers buy one get one free promotions
![Page 25: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/25.jpg)
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
![Page 26: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/26.jpg)
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
![Page 27: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/27.jpg)
BDD Patterns: Tables
Scenario: Winning positionsGiven a board layout:
| 1 | 2 | 3 || O | O | X || O | | || X | | X |
When I mark X at middle rightThen I win
![Page 28: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/28.jpg)
What makes a bad feature file
Long sentences Repetitious sentences Repetitive scenarios
A never ending story Commentary And another thing
![Page 29: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/29.jpg)
BDD Patterns: Examples
Scenario: Winning positionsGiven 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 |
![Page 30: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/30.jpg)
Terry's Chocolate Oranges sold for just 29p eachTwo simultaneous promotions: three-for-£5 offer buy-one-get-one-free
Equals: £2.75 product Sells for 29p
![Page 31: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/31.jpg)
Yum!
![Page 33: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/33.jpg)
Lifetime BDD Awards
@tastapod
@lunivore
@gojkoadzic
![Page 34: TDD & BDD in F# at Progressive F# Tutorials 2011](https://reader035.vdocuments.us/reader035/viewer/2022081507/55491152b4c90565458beb12/html5/thumbnails/34.jpg)
Q & A