Test Driven Development Coding Kata

Test Driven
Coding Katas
What is
What is TDD
What is a
What is a Kata?
Karate Katas
Sand the floor
Wash the car
Paint the fence
Right the circle
Wax on – right hand circle
Paint up
Left the circle
Wax off – left hand circle
Paint down
Breath in breath out
Breath in breathe out
Breath in out
(no look me look fence!)
What is a Coding Kata?
As a group, software developers don’t practice enough. Most of our
learning takes place on the job, which means that most of our mistakes
get made there as well. Other creative professions practice: artists carry
a sketchpad, musicians play technical pieces, poets constantly rewrite
works. In karate, where the aim is to learn to spar or fight, most of a
student’s time is spent learning and refining basic moves. The more
formal of these exercises are called kata.
Dave Thomas
http://codekata.pragprog.com, 2007
TDD Katas
1. You are not allowed to write any production
code unless it is to make a failing unit test
2. You are not allowed to write any more of a
unit test than is sufficient to fail; and
compilation failures are failures.
3. You are not allowed to write any more
production code than is sufficient to pass
the one failing unit test.
TDD Kata
Roman Numerals Kata
Return a string with the
Roman Numerals for a given
Remember to follow the rules
of TDD.
Wax on, wax off, breathe!
TDD Katas
Fibonacci Sequence
Print the sum of the
previous two numbers
If divisible by 3, fizz
If divisible by 5, buzz
If divisible by both , fizzbuzz
1 2 fizz 4 buzz fizz 7
8 fizz buzz 11 fizz 13
14 fizzbuzz
TDD katas
Tennis scoring
Bowling scoring
String Calculator
Pacman needs to move about on a grid.
Given - something
When – something
Then - something
Why do this
One of the reasons TDD is
hard for newcomers is that it
is very explicit about the
baby-step nature of the
changes you make to the
code. You simply are not
allowed to add anything more
than the current tests require.
And for experienced
developers, this is very hard
to do, especially when
working on real code.
Why do this
TDD is not taking
TDD cadence
System complexity
Try new libraries
Learn shortcuts
Learn from other developers
Understand a new language
Understand an old language
Its fun
Styles of Kata
◦ Daily
◦ Weekly
◦ Write a test, pass a test, pass the keyboard
◦ Pass a test, write a test , pass the keyboard
◦ 4 person group
◦ n Pairs
• Whether to use one assert or multiple asserts in each test
• When to use mocks and when its better to use stubs
• Is it ok to change the access level of methods from private to protected or
• TDD/OO vs functional programming
• How complex problems broken into small chunks
• It takes discipline to not make 'improvements' to the code for which there
is not yet a failing test! Its so tempting to make untested changes, but
doing so usually ends in an unhappy experience and gets rolled back.
• The logic of implementing the 'simplest thing that could possibly work‘
Lessons Learnt
Mac/Windows keyboards are
not the same!
Don’t rely on network access
Sit together
Pairs of people new to TDD need
Do the kata yourself before
supervising a group session
Expect inconsistent attendance

similar documents