Coding Dojo: Adding Tests to Legacy Code (2014)
-
Upload
peter-kofler -
Category
Technology
-
view
271 -
download
1
description
Transcript of Coding Dojo: Adding Tests to Legacy Code (2014)
![Page 1: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/1.jpg)
Coding Dojo:Adding Tests to the
Ugly Trivia Legacy CodeFeb. 2014
Peter Kofler, ‘Code Cop’@codecopkofler
www.code-cop.orgCopyright Peter Kofler, licensed under CC-BY.
![Page 2: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/2.jpg)
Peter Kofler
• Ph.D. (Appl. Math.)
• Professional SoftwareDeveloper for 14 years
• “fanatic about code quality”
• I help development teams
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 3: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/3.jpg)
Expectations?
![Page 4: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/4.jpg)
Coding Dojo Mindset
● Safe place outsidework
● We are here to learn● Need to slow down● Focus on doing it right● Collaborative Game
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 5: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/5.jpg)
Dojo Structure
● Introduction 15'● Coding 60'● Break● Interim (Retrospective) 15'● Coding 60'● Break● Coding 60'● Retrospective 30'
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 6: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/6.jpg)
Legacy Code Skills
● Understanding Legacy Code● Breaking Dependencies● Bringing Code Under Test ● Refactoring Mercilessly
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 7: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/7.jpg)
Ugly Trivia
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 8: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/8.jpg)
Legacy Codebase “uglytrivia“
● Get the codehttps://github.com/jbrains/trivia
● An implementation of Trivial Pursuit● http://en.wikipedia.org/wiki/Trivial_Pursuit● players take turns to answer trivia questions● questions are split into categories● players collect coins for right answers
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 9: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/9.jpg)
Requirements
● Choose a testing framework● Create tests, cover all cases
● May need to extract code to do that
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 10: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/10.jpg)
Don't Focus on Getting it Done.F0cus on Doing
It Perfectly.
![Page 11: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/11.jpg)
→Practice
![Page 12: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/12.jpg)
Extract Pure Functions
● find a piece of code that can be moved into a separate function by using “Extract Method“
● replace all external dependencies within this function with independent parameters
● add a test for that function● refactor the tested code as needed
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 13: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/13.jpg)
Extract Class
● isolate functionality that somehow relates and can be separated from other behaviour
● turn isolated methods into pure functions
● extract these pure functions into a separate class
● add tests for that new class
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 14: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/14.jpg)
Closing Circle
● What did you learn today?
● What surprised you today?
● What will you do differently in the future?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 15: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/15.jpg)
Peter Kofler@codecopkofler
www.code-cop.org
Idea by
J.B.Rainsberger@jbrains
https://github.com/jbrains/trivia
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
![Page 16: Coding Dojo: Adding Tests to Legacy Code (2014)](https://reader034.fdocuments.in/reader034/viewer/2022042521/54c0e9b84a795970718b4591/html5/thumbnails/16.jpg)
CC Images● Dojo http://www.flickr.com/photos/49715404@N00/3267627038/● Todos http://www.flickr.com/photos/kylesteeddesign/3724074594/● Trivia http://www.flickr.com/photos/thehoneybunny/207992667/● Wants you http://www.flickr.com/photos/shutter/105497713/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY