Test Driven Development
Erinda Jaupaj
@ErindaJaupi
Valentina Servile
@EsseValentina
goes to
Introduction
What is Test Driven Development?
Introduction
What is Test Driven Development?
Introduction
What is Test Driven Development?
Maybe we should first ask ourselves...
Introduction
What is Test Driven Development?
What is a Test?
Introduction: what is a test?
A test is an assertion about how your
code should work
Introduction: what is a test?
It’s automated
Introduction: what is a test?
It has a binary output
(It’s either passing or failing)
Introduction: what is a test?
It begins with a precondition
(setup)
Introduction: what is a test?
It invokes a unit of work in the system
(trigger)
Introduction: what is a test?
It makes an assertion about the result
Setting up the
precondition
Invoking the
desired behavior
Asserting about
what happened
Patterns
Back to our
main topic...
Introduction
What is Test Driven Development?
Introduction
What is Test Driven Development?
It’s a technique where you let tests
guide your development workflow
Introduction: how do I TDD?
It works in 3 steps:
Introduction: how do I TDD?
It works in 3 steps:
• Write a failing test
Introduction: how do I TDD?
It works in 3 steps:
• Write a failing test
• Write just enough code to make it pass
Introduction: how do I TDD?
It works in 3 steps:
• Write a failing test
• Write just enough code to make it pass
• Refactor your mess
Introduction: how do I TDD?
It works in 3 steps:
• Write a failing test
• Write just enough code to make it pass
• Refactor your mess
Rinse and
Repeat!
Introduction: how do I TDD?
REFACTOR
FAIL
PASS
TDD
Introduction
What a waste
Of time!!!
Just make it work!!!
Patterns
TDD
Hands on
TDD Hands on
The requirements:
• Print numbers in sequence
• If the number is divisible by 3, print “Fizz”
• If the number is divisible by 5, print “Buzz”
• If divisible by both, print “FizzBuzz”
Patterns
The
FizzBuzz Kata
Patterns
Ta-Da!
Wrapping up: what is TDD for?
Okay, so what?
Wrapping up: what is TDD for?
But...
Wrapping up: what is TDD for? ...Design!
You HAVE to think of the edge cases
Wrapping up: what is TDD for? ...Design!
It often leads you to a simpler solution
Wrapping up: what is TDD for? ...Design!
Makes you write pretty object interfaces
Wrapping up: what is TDD for? ...Design!
You HAVE to think OO. And keep it simple.
Wrapping up: what is TDD for? ...Design!
It’s easy to add new features!
Wrapping up: what is TDD for? ...also, tests
...and to check if you broke the old ones
Wrapping up: what is TDD for? ...also, tests
...I’ll write my tests after.
Wrapping up: what is TDD for? ...also, tests
The code is self documented
TDD vs Traditional
Wrapping up: when NOT to use TDD?
• The application has little to no
business logic (CRUD?)
• You are building a prototype
• Quality is not important
Wrapping up: when to use TDD?
• The application has complicated
business logic
• You don’t know how your
implementation will look like
• Correctness is crucial
• The project is gonna be long lived
and frequently retouched
Patterns
Give it a try!
www.xpeppers.com
/xpepperssrl@xpeppers
Thanks!
Any questions?
Resources:
• http://www.jamesshore.com/Agile-Book/test_driven_d
evelopment.html
• https://www.amazon.com/Test-Driven-Development-
Kent-Beck/dp/0321146530
• http://codingdojo.org/kata/

Test Driven Development SpeedRun