This document discusses test-driven development (TDD) and behavior-driven development (BDD). It defines TDD as a process of writing automated tests before code to define desired functionality, then writing minimum code to pass tests and refactoring. BDD combines TDD techniques with domain-driven design and aims to facilitate collaboration between developers and business stakeholders. The document provides an example of using BDD to specify scenarios for generating life insurance risk quotes. It also outlines how to structure tests in TestBox and run test bundles.
Intro to TDD & BDD - Test Driven Development and Behaviour Driven Development
1. Intro
to
TDD
&
BDD
Test Driven Development
& Behaviour Driven Development
Kev McCabe
In to The Box 2015
Sunday, 19 April 15
2. Who am I?
• Kev McCabe AKA @bigmadkev
• Freelance Code Smith
& Agile Coach
• Developer for over 18 years
• Worked in TV Broadcast,
Healthcare, Travel & Finance
• Adobe Community Professional
3. Agenda
• Types of testing
• Why Test
• TDD Intro
• BDD Intro
• TestBox BDD
8. What is TDD
Test-driven development (TDD) is a software
development process that relies on the
repetition of a very short development cycle:
first the developer writes an (initially failing)
automated test case that defines a desired
improvement or new function, then
produces the minimum amount of code to
pass that test, and finally refactors the new code
to acceptable standards
9. What is TDD
What it is
• A tool to drive design
• Developer focused
• Works with BDD
• Non-intuitive but powerful
tool
What it is not
• About testing
• For the faint hearted
• A silver bullet
• Easy
11. What is BDD
In software engineering, behavior-driven development
(BDD) is a software development process that
emerged from test-driven development (TDD).Behavior-
driven development combines the general techniques and
principles of TDD with ideas from domain-driven
design and object-oriented analysis and design to
provide software developers and business analysts
with shared tools and a shared process to
collaborate on software development, with the aim of
delivering “software that matters”
12. What is BDD
• Dan North - http://dannorth.net/introducing-bdd
• Ubiquitous language
– existing or being everywhere at the same time : constantly
• Promotes communication & collaboration between
– Developers + business analysts + stakeholders
• Focuses on stories or requirements rather than on functions
• Focuses on what a system should do and not on how it should be
implemented
– Better readability and visibility
– Verify that software works but also that it meets customer
expectations
19. Scenario One
Given a customer under 30 years
When they request a life insurance quote
Then we return an insurance risk of low
20. Given a customer under 55 years
When they request a life insurance quote
Then we return an insurance risk of med
Scenario Two
21. Given a customer over 55 years
When they request a life insurance quote
Then we return an insurance risk of high
Scenario Three
22. Given a customer between
<lowerLimit> & <upperLimit>
When they request a life insurance quote
Then we return an insurance risk of <riskResult>
|lowerLimit|upperLimit|riskResult|
|18 | 29 | low |
|30 | 54 | med |
|55 | 65 | high |
Scenario Outline
23. What if they smoke?
What if they drink alcohol?
What if they have known health issues?
What about people under 18 and over 70?
Questions Raised
24. In order not to insurance under & over aged
customers
as an insurance company,
I want to raise an exception
Additional Stories
25. We have learnt about our domain
The customer worries about age limits more
than anything else
We also know that other items are upcoming
but …… we don’t need to develop them until
we have that story!
What we have learnt
26. Having conversations
Is more important than
capturing conversations
Is more important than
automating conversations
www.slideshare.net/lunivore/behavior-‐driven-‐development-‐11754474
Liz
Keogh
@lunivore
27. describe(“Customer is between 18 & 29”, function() {
it( “will return an insurance risk of low”, function() {
var customer = new customerBuilder().withAge(24).build();
expect(riskService.generateRiskRating(customer))
.toBe(“low”);
})
})
describe(“Customer is between 30 & 54”, function() {
it( “will return an insurance risk of med”, function() {
var customer = new customerBuilder().withAge(37).build();
expect(riskService.generateRiskRating(customer))
.toBe(“med”);
})
})
Scenario to TestBox
28. BDD & TDD
From
Growing
Object-‐Oriented
Software
by
Nat
Pryce
and
Steve
Freeman
29. TestBox is a next generation testing framework for ColdFusion that is based
on BDD (Behavior Driven Development) for providing a clean obvious
syntax for writing tests. It contains not only a testing framework, runner,
assertions and expectations library but also integrates with MockBox for
mocking and stubbing. It also supports xUnit style of testing and MXUnit
compatibilities.
32. Test Bundle CFC
• No matter what style, you start with a test
bundle CFC
• Inherits from testbox.system.BaseSpec or not!
• URL runner caveat
• Get’s lots of methods and properties for testing
• TestBox will then execute all tests within 1 or
more bundles
33. Running your bundles
• Execute bundle (if using inheritance) via the URL
– http://mysite/test/bundle.cfc?method=runRemote
• Using the TestBox Class: testbox.system.TestBox
– Bundle(s) Runner
– Directory Runner
– SOAP Runner
– HTTP/REST Runner
– ANT Runner
– Custom Runners
• What’s the output? We call this reporters
34. Reporters
• ANTJunit : A specific variant of JUnit XML that works with the ANT junitreport task
• Codexwiki : Produces MediaWiki syntax for usage in Codex Wiki
• Console : Sends report to console
• Doc : Builds semantic HTML to produce nice documentation
• Dot : Builds an awesome dot report
• JSON : Builds a report into JSON
• JUnit : Builds a JUnit compliant report
• Raw : Returns the raw structure representation of the testing results
• Simple : A basic HTML reporter
• Text : Back to the 80's with an awesome text report
• XML : Builds yet another XML testing report
• Tap : A test anything protocol reporter
• Min : A minimalistic view of your test reports
35.
36. Let’s walk through an example
• The life insurance example
• We’ll use a BDD Spec to tell us when we’re done
• We’ll use TDD to drive the design of our code
37. What the future holds!
• Grunt JS Tasks
• NodeJS Runners and Watchers
• Sublime Runner
• More Reporters
• More focus on automation
• Gherkins support