The document discusses test-driven development (TDD) and behavior-driven development (BDD) when testing in F#. It outlines some popular unit testing frameworks that can be used in F# like NUnit, xUnit, and MsTest. It also discusses fluent interfaces like FsUnit and FsTest for writing tests. The document then discusses the principles of agile development and BDD, including writing user stories and acceptance tests in a natural language. It notes benefits of TDD and BDD like facilitating change, providing documentation, and improving design. Finally, it discusses some BDD frameworks for F# like SpecFlow, TickSpec, and NaturalSpec and provides an example of writing a BDD specification.
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
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
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
http://www.stickyminds.com/sitewide.asp?Function=edetail&ObjectType=ART&ObjectId=13833&tth=DYN&tt=siteemail&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.
This is a description of what BDD is and how it relates to TDD.
BDD also known as Acceptance Test Driven Development etc.