This is a session to teach test driven development / design. It has been presented in various cities throughout North America. This is the final slides from the Agile 2013 conference in Nashville. Now includes all bricks you need to build your own kits.
5. What is the goal of TDD?
It creates clean code that works ~ Ron Jefferies
6. TDD
It is a predictable way to develop. You know when you
are finished, without having to worry about a long bug
trail.
7. TDD
It gives you a chance to learn all of the lessons that the
code has to teach you. If you only slap together the first
thing you think of, then you never have time to think of
a second, better thing.
22. Same thing for house
Blah, blah, awesome recreation by speaker...everyone
is extremely impressed and are thinking this might be
the best session of the whole conference.
23. We need a new test
The house is taller then the person.
Assert.IsTrue(house.height > person.height);
30. We need a new test
Is the house wider then the person? No?
We failed another test! Awesome! We are learning a lot
about improvements that are needed to our code.
Let’s do the minimum to pass the test.
Any duplication to remove?
31. We need a new test
Can your person fit in the house? Yikes! No.
We failed another test! Awesome! We are learning so
much about what our customer needs.
Let’s do the minimum to pass the test.
Any duplication to remove?
32. Exercise - 3 Partners!
Break into groups of
two for this next
exercise.
When developers do
this we call it Pair
Programming
Berkley photo from the web
34. Let’s Practice!
Work together to come up with some new tests
Keep building to minimally pass tests
Don’t worry about Refactoring for now
Here’s a few if you get stuck:
Is the house at least x inches/cm tall?
Is the tree the same size as the house?
Is the animal smaller than the person?
36. Review
Let’s take a minute to walk around and look at
everybody’s creations!
Taking breaks and stretching your muscles (eyes, legs,
arms, back) is very important to stay healthy.
37. Apology
You may have to break your wonderful new structures
for the components for the next section.
Don’t worry, there is more building to come!
Please do take a photo. Remember @BillyGarnet and
@mike_bowler if your tweeting about the amazing time
your having!
38. Refactoring
Refactoring is the process of changing a software
system in such a way that it does not alter the external
behaviour of the code yet improves its internal
structure.
~Martin Fowler
39. LEGO Refactoring
We will be using bricks
with two points on top
and panels with two
points on top.
40. Stack up big (normal height)
bricks like this:
brown-red-blue-blue-red-
green-yellow-red-green
brown on top and green at
the very bottom
Build our program
41. Your group of lego bricks represents a program.
Each one of these colour bands represents some logic
in your code.
Class and Methods
42. Duplication
Remember DRY (Don’t Repeat Yourself).
Notice how there are repeats of the same colour
bands. This is duplication in our code. Let’s fix this!
43. Extract Method
We are going to start by extracting a method. We will
replace the first big red block with a small red panel.
Put the structure back together and put the big red
block on the bottom.
This small red panel simply tells the program to go to
run the big red block code.
44. Remove Duplication
Now let’s replace the other big red blocks with the flat
red panels.
We don’t need to move these big red blocks to the
bottom since we already have that code there.
45. Keep Going!
Let’s do (Extract Method) on that big blue section.
Even though it’s not repeated, it would be easier to
read the program with that blue blob at the bottom.
47. Readability
I really don’t like the way we are mixing bricks and flat
panels at the top of our program.
Let’s extract brown and yellow as well (Composite
Method)
48. Clarity
Remember some of the requirements for good
software? It needs to be easy to read and update.
Let’s re-arrange these big bottom blocks to match the
order of the flat panels that are above them.
49. Super Fast Break
Stand up and stretch - really, it’s important!
Share something you’ve learned with a
neighbour!
50. Exercise 4 -Team Build
Each table will come up with a large structure with lots
of parts to build.
You will be a software team, working in pairs,
contributing to the large team structure (the build) at
51. Decide on an idea
Shh...don’t tell the other tables.
(Jeopardy music...)
52. Break it into components
Take a minute to write out a few of the components
that need to be built (product backlog).
Each pair will build a component through TDD.
We will then add the sections to the big project. Make
sure they don’t break the rest of the tests.
We will repeat this a few times.
53. Demo time!
A few teams will now present their creation.
Please share the tests that you came up with and point
out the solution.
54. Review
Test-Driven Development / Design
Refactoring
Pair Programming
A bit of developer speak
Experience working on a software team