ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Test Driving Legacy Code
Breaking out of the ¡°Legacy Code Dilemma¡±
About me¡­
Developer since 1994
(C++ used to be my friend¡­)
Agile Coach since 2009
fernando.a.cuenca@gmail.com
@fer_cuenca
Big Thanks to our
Sponsor!
http://digitalfactory.scotiabank.com
Agenda
TDD in the context of Legacy Code
Practice Session 1 + Debrief
BREAK
Practice Session 2 + Debrief
So, what is ¡°Legacy Code¡±
anyways?
Code that
actively prevents
you from making
changes
Code we¡¯re
afraid to change
Code where the
design makes
more design
decisions than
the programmer
Code without
Unit Tests
you could
have a
¡°magic
button¡±¡­
Pecha Kucha @ OOP 2015 "Is TDD dead?
https://www.youtube.com/watch?v=9NANcPTbDBQ
Start
Here
TDD
Write a
failing
test
Make it
pass
Improve
the
Design
The Legacy Code Dilemma
Michael Feathers
¡°Working Effectively with Legacy Code¡±
Pinning Down
Behaviour
Your turn now!
2 Practice sessions + Debrief
We need to choose a common Programming
Language
Java
C#
Javascript
Find a partner (we¡¯ll switch for Session 2)
Log in to my Cyber-Dojo:
http://cyberdojo.ddns.net
Welcome to Ugly Trivia!
What does the code do?
What are the different RESPONSIBILITIES?
How ¡°good¡± or ¡°bad¡± is this code? Why?
How much ¡°Technical Debt¡± does it have?
Can you identify two distinct kinds of tests?
What is the purpose of each?
Key Ideas
Adding More Characterization
Tests
What kinds of things are displayed? When?
What¡¯s the minimum number of players?
What happens when a player rolls?
How does the current location change?
How are categories selected?
How are coins awarded?
What¡¯s the order of the players?
How big is the board? How is it traversed?
What happens when the answer is correct?
Incorrect?
What are the rules around the ¡°penalty box¡±?
Debrief: What was it like?
What are most important insights you gained
from the session?
What was helpful / not-helpful?
What will you do differently in the next session?
Let¡¯s fix some defects!
Fix typo when answering correctly ("Answer was
corrent")
Terminate nicely instead of throwing exceptions:
when questions run out
when rolling before adding players
Let¡¯s add some new
features!
Backlog
1. Display the winner's
name when the game
ends
2. Display output in
multiple languages
Guidelines
Cover, then modify
Can you test-drive a
replacement?
Are your tests passing
all the time?
How small are your
steps? Can you make
them smaller?
Large-Scale Refactoring
New Features
1. Configurable board size
2. New Category: Politics
3. When questions run out (in
any category), the game ends
and the player with the most
coins wins
4. Different categories pay
different amount of coins
when answered correctly
5. if 2 people in a row answer
incorrectly, the order of
players inverts
Guidelines
Pick a feature to work
on
Agree on a ¡°good
design¡± for it.
Sketch general
incremental steps to
get there
The Mikado Method (https://mikadomethod.wordpress.com)
Debrief: What was it like?
What are most important insights you gained
from this session?
What was the overall feeling?
How does the result compares to what you
initially thought the outcome might be?
How/Where could this approach be useful?
What will you do differently tomorrow, back in the
office?
Learning more
Thank you!
And please, complete the feedback forms!!

More Related Content

Test Driving Legacy Code Mini Workshop

  • 1. Test Driving Legacy Code Breaking out of the ¡°Legacy Code Dilemma¡±
  • 2. About me¡­ Developer since 1994 (C++ used to be my friend¡­) Agile Coach since 2009 fernando.a.cuenca@gmail.com @fer_cuenca
  • 3. Big Thanks to our Sponsor! http://digitalfactory.scotiabank.com
  • 4. Agenda TDD in the context of Legacy Code Practice Session 1 + Debrief BREAK Practice Session 2 + Debrief
  • 5. So, what is ¡°Legacy Code¡± anyways?
  • 6. Code that actively prevents you from making changes Code we¡¯re afraid to change Code where the design makes more design decisions than the programmer Code without Unit Tests
  • 7. you could have a ¡°magic button¡±¡­ Pecha Kucha @ OOP 2015 "Is TDD dead? https://www.youtube.com/watch?v=9NANcPTbDBQ
  • 9. The Legacy Code Dilemma Michael Feathers ¡°Working Effectively with Legacy Code¡±
  • 11. Your turn now! 2 Practice sessions + Debrief We need to choose a common Programming Language Java C# Javascript Find a partner (we¡¯ll switch for Session 2) Log in to my Cyber-Dojo: http://cyberdojo.ddns.net
  • 12. Welcome to Ugly Trivia! What does the code do? What are the different RESPONSIBILITIES? How ¡°good¡± or ¡°bad¡± is this code? Why? How much ¡°Technical Debt¡± does it have? Can you identify two distinct kinds of tests? What is the purpose of each?
  • 14. Adding More Characterization Tests What kinds of things are displayed? When? What¡¯s the minimum number of players? What happens when a player rolls? How does the current location change? How are categories selected? How are coins awarded? What¡¯s the order of the players? How big is the board? How is it traversed? What happens when the answer is correct? Incorrect? What are the rules around the ¡°penalty box¡±?
  • 15. Debrief: What was it like? What are most important insights you gained from the session? What was helpful / not-helpful? What will you do differently in the next session?
  • 16. Let¡¯s fix some defects! Fix typo when answering correctly ("Answer was corrent") Terminate nicely instead of throwing exceptions: when questions run out when rolling before adding players
  • 17. Let¡¯s add some new features! Backlog 1. Display the winner's name when the game ends 2. Display output in multiple languages Guidelines Cover, then modify Can you test-drive a replacement? Are your tests passing all the time? How small are your steps? Can you make them smaller?
  • 18. Large-Scale Refactoring New Features 1. Configurable board size 2. New Category: Politics 3. When questions run out (in any category), the game ends and the player with the most coins wins 4. Different categories pay different amount of coins when answered correctly 5. if 2 people in a row answer incorrectly, the order of players inverts Guidelines Pick a feature to work on Agree on a ¡°good design¡± for it. Sketch general incremental steps to get there
  • 19. The Mikado Method (https://mikadomethod.wordpress.com)
  • 20. Debrief: What was it like? What are most important insights you gained from this session? What was the overall feeling? How does the result compares to what you initially thought the outcome might be? How/Where could this approach be useful? What will you do differently tomorrow, back in the office?
  • 22. Thank you! And please, complete the feedback forms!!

Editor's Notes

  1. We tend to associate two ideas with ¡°Legacy Code¡±: old, and messy.
  2. Cyber-dojo start-point: Ugly Trivia / With Tests Ask people to review the code in pairs Distribute responsibilities page (if people need guidance)
  3. Distribute Characterization test list (if people are lost)
  4. Focus is to practice ¡°Cover, then modify¡± Distribute refactoring diagrams == BREAK ==