tdd & bdd in f# at progressive f# tutorials 2011

Post on 06-May-2015

2.698 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

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

TDD & BDDTesting 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

Customers

Business AnalystTesters

Developer

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

Cuke4Nuke NBehave StorEvil SpecFlow TickSpec

Internal DSL

MSpec NaturalSpec NSpec SpecsFor StoryQ

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

First Steps in BDD on .Net

• Shell• C# & F#

StorEvil

• Visual Studio• C#

SpecFlow

• F# & C#• VS & Shell

?

?

Visual Studio

NUnitGherkin

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 positionsGiven a board layout:

| 1 | 2 | 3 || O | O | X || O | | || X | | X |

When I mark X at middle rightThen 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 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 |

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

Yum!

BDD Books

Lifetime BDD Awards

@tastapod

@lunivore

@gojkoadzic

Q & A

top related