1. Using TDD to understand
Legacy Codes
Copyright 2013
Suradet Jitprapaikulsarn
www.ajarnsuradet.com
2. Revision 1.0 Using TDD to understand Legacy Codes2
Creative Commons License 3.0
This work is licensed under the Creative
Commons Attribution-NonCommercial-
ShareAlike 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/3.0/
or
send a letter to Creative Commons, 171 Second
Street, Suite 300, San Francisco, California,
94105, USA.
3. Revision 1.0 Using TDD to understand Legacy Codes3
You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work
Under the following conditions:
Attribution — You must attribute the work in the
manner specified by the author or licensor (but not in
any way that suggests that they endorse you or your
use of the work).
Noncommercial — You may not use this work for
commercial purposes.
Share Alike — If you alter, transform, or build upon
this work, you may distribute the resulting work only
under the same or similar license to this one.
4. Revision 1.0 Using TDD to understand Legacy Codes4
With the understanding that:
• Waiver — Any of the above conditions can be waived if
you get permission from the copyright holder.
• Public Domain — Where the work or any of its
elements is in the public domain under applicable law,
that status is in no way affected by the license.
• Other Rights — In no way are any of the following rights
affected by the license:
– Your fair dealing or fair use rights, or other applicable copyright
exceptions and limitations;
– The author's moral rights;
– Rights other persons may have either in the work itself or in how
the work is used, such as publicity or privacy rights.
Notice — For any reuse or distribution, you must make
clear to others the license terms of this work. The best
way to do this is with a link to this web page.
5. Revision 1.0 Using TDD to understand Legacy Codes5
Topics
• Typical TDD Process
• Legacy Code
• Approaches for working with legacy code
• More information
• About Me
6. Revision 1.0 Using TDD to understand Legacy Codes6
Typical TDD
• “Clean Code that work” – Ron Jeffries
• 2 Simple rules – Kent Beck
– Write new code only if a test has failed
– Get rid of duplication
7. Revision 1.0 Using TDD to understand Legacy Codes7
TDD Mantra
Red
GreenRefactor
Write a test
that will fail
Make code to
pass tests
Improve the
codes & tests
Source:
K. Beck, Test-Driven
Development by Example,
Addison-Wesley, 2002
8. Revision 1.0 Using TDD to understand Legacy Codes8
Typical TDD Process
Add a
Test
Run
Tests
Make a
change[Failed]
[Passed]
Run
Tests
[Failed]
[Passed but not done]
[Passed
& Done]
9. Revision 1.0 Using TDD to understand Legacy Codes9
Suitable Scenarios
• Perfect for new code
• Assume that called elements are
trustworthy and testable
• Green field
Well-understood, testable code
11. Revision 1.0 Using TDD to understand Legacy Codes11
Legacy Code
• Existing code
• A lot of doubts about elements
• Some elements have some problems
• Brown field
12. Revision 1.0 Using TDD to understand Legacy Codes12
Approaches for working with legacy
code
• Wrapped code
• Sprout method
• ATDD / BDD
• Etc
13. Revision 1.0 Using TDD to understand Legacy Codes13
More information
1. K. Beck, Test-Driven Development by
Example. Addison-Wesley, 2003.
2. M. Features, Working Effectively with
Legacy Code. Prentice Hall, 2004.
14. Revision 1.0 Using TDD to understand Legacy Codes14
About Presenter
• Suradet Jitprapaikulsarn, Ph.D.
• Lecturer
• Department of Electrical and Computer
Engineering, Naresuan University,
Phitsanulok
• Email: suradet.j@gmail.com
• Facebook: Suradet Jitprapaikulsarn
15. Revision 1.0 Using TDD to understand Legacy Codes15
About Me (Cont.)
• Apply PSP since 1997
• Apply TDD since 1999
• 1st
Thai ScrumMaster, since 2009
• Was the only authorized PSP instructor in
Southeast Asia
• 1st
Certified PSP developer
• 5 times CMMI appraisal team member
• Only Asian instructor invited for Software
Architecture workshop at SEI, 7 year in a row
(2006 – 2012)
Editor's Notes
Revision History ------------------------ Revision 1.0 (2013-03-23) 1st release for BugDay Bangkok 2013