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

34
TDD & BDD Testing in F# Phil Trelford and Chis Marinos 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.zip

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

Page 1: TDD & BDD in F# at Progressive F# Tutorials 2011

TDD & BDDTesting in F#

Phil Trelford and Chis Marinos

Progressive F# Tutorials 2011

Page 2: TDD & BDD in F# at Progressive F# Tutorials 2011

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

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

Fluent Interfaces

FsUnit FsTest NaturalSpec

Page 5: TDD & BDD in F# at Progressive F# Tutorials 2011

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

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

Collaboration

Customers

Business AnalystTesters

Developer

Page 8: TDD & BDD in F# at Progressive F# Tutorials 2011

User Stories

Page 9: TDD & BDD in F# at Progressive F# Tutorials 2011

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

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

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

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

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

Team Workshops

Page 15: TDD & BDD in F# at Progressive F# Tutorials 2011

BA + Developer + QA

Page 16: TDD & BDD in F# at Progressive F# Tutorials 2011

Testers find holes

Page 17: TDD & BDD in F# at Progressive F# Tutorials 2011

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

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

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

Look no hands

Page 21: TDD & BDD in F# at Progressive F# Tutorials 2011

Look no hands

Page 22: TDD & BDD in F# at Progressive F# Tutorials 2011

TickSpec

Page 23: TDD & BDD in F# at Progressive F# Tutorials 2011

Demo

Page 24: TDD & BDD in F# at Progressive F# Tutorials 2011

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

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

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

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

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

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

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

Yum!

Page 32: TDD & BDD in F# at Progressive F# Tutorials 2011

BDD Books

Page 33: TDD & BDD in F# at Progressive F# Tutorials 2011

Lifetime BDD Awards

@tastapod

@lunivore

@gojkoadzic

Page 34: TDD & BDD in F# at Progressive F# Tutorials 2011

Q & A