TDD
Test Driven Development
David Paluy
Jul 2015
Agenda
1. When do we need to write tests
2. The TDD process
3. Glossary
Test Driven Development
You don’t have to do TDD,
You should do TDD.
When do we need to write tests?
If my code
works perfectly,
why should I write tests
for it?
Realization 1
Testing breeds confidence
Confidence
● Modular code
● Many changes
● Refactoring
If there are NO TESTS, you should be worried making changes!
“Write a failing automated test
before changing any code” - Kent Beck
Remember
When do we need to write tests?
So, if the code
works perfectly, and I’m
never going to change it,
then why should I write
tests?
Realization 2
If you write tests before you write your code,
you end up writing a better code
If I write the test first,
● It forces me think before I code
● Code is more focused and clear
● I know when I’m finished, because all the
tests pass
When do we need to write tests?
So, if the code
works perfectly, and I’m
never going to change it
and the design is already
flawless,
then why should I write
tests?
Realization 3
Well written tests are just as good, if not
better than documentation
Yoga Instructions
1. Kneel down
2. Put your hands flat in the ground
3. Lift your feet off the ground and balance on
your hands
4. Put your knees ahead of your hands
5. Stretch out your back so your body is
perpendicular to the ground
Yoga Instructions
Yoga Instructions
Examples > Comments
When do we need to write tests?
So, if the code
works perfectly, and I’m
never going to change it
and the design is already
flawless and it is totally
readable and
understandable,
then why should I write
tests?
The moral
Learning Test Driven Development
The TDD process
● Write specifications
● Write tests
● Write code
The TDD process
The TDD process
Glossary
● Unit Tests
● Integration Tests
● Acceptance Tests
● Mocks, Stubs
Unit Test - Method to verify isolated
units of code
● Checks a single assumption about the
behavior of the unit
● Fast running tests
● Quick to debug
● Is hitting DB - is OK?
Integration Tests
● Tests software modules as a group
● Tests integration points
● Slower than Unit tests
Acceptance tests
● End-to-end test cases of:
happy user journeys and critical failure scenarios
● Production like environment
● Manual or Automated
Mocks vs Stubs
Mock Objects are special case objects that
mimic real objects for testing.
Stubs provide canned answers to calls made
during the test
Test Driven Development
Inspect
+
Adapt
Test Driven Development
Apply
Inspect
Adapt
Test Driven Development
Apply
Inspect
Adapt
If you haven’t done it first, you don’t know what you are talking about!
“Any fool can write code that a computer can
understand.
Good programmers write code that humans
can understand.”
Martin Fowler, 2008.

Tdd - Test Driven Development