SlideShare a Scribd company logo
1 of 30
100% Confident with Legacy
Code
Johan MARTINSSON
Developer - Independent
martinsson.johan@gmail.co
m
@johan_alps
Rémy SANLAVILLE
Developer - Orange Software Expert
remy.sanlaville@orange.com
@sanlaville
Working with Legacy Code
Working with Legacy Code
Refactoring Legacy Code with Object
Calisthenics2012 - 2013
Anonymous Developers - Season 1
Working with Legacy Code
100% Confident with Legacy Code
2014
Anonymous Developers - Season 2
Testing Legacy Code - Blockers
Integration tests are too long
Unit tests are too coupled to the source code
Hard and long to write tests
Testing Legacy Code
100% Confident with Legacy Code
2014
Anonymous Developers - Season 2
Testing Legacy Code
100% Confident with Legacy Code
2014
Anonymous Developers - Season 2
Testing Legacy Code
Don’t forget to replace
temporary refactoring
tests
Trivia Challenge http://www.hasbro.com/games/en_US/shop/details.cfm?R=93C6EE71-
6D40-1014-8BF0-9EFBF894F9D4:en_US
https://github.com/jbrains/trivia
It simulates a trivia game
using a randomizer
for correct and wrong answers
How long do you need to
reach ~100% code coverage ?
Trivia Challenge
https://github.com/jbrains/trivia
http://www.hasbro.com/games/en_US/shop/details.cfm?R=93C6EE71-
6D40-1014-8BF0-9EFBF894F9D4:en_US
It works well because there
are no dependencies
1
1
Serialize game state and
compare it with Approval Tests
1
Cover all branches by
variying the results of the
randomizer
2
2
Server 1
Server 2
EncodeAudioLegacy Challenge
Remote Server 1
Audio File encoding
HTTPS Server 2
Audio File Encoded
Audio File
Audio File available
at Remote Server 1
Encoded Audio File
available
download upload
Encode Audio Engine
Baby Steps
Step0: Development environment validation
Step1: String comparison with ApprovalTests
Step2: Branch coverage by input parameter variation
Step3: Serializing a complex type
Step4: Mocking web services
Step5: Capturing side effects
Step 0: Development environment validation
EclEmmaJUnit
Technical Solution: Unit Testing + Code Coverage Tool + Diff
Tool
Context: Launch UT + Code Coverage + String comparison
Server 1
Remote Server 1
Audio File
download
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
Audio File Encoded
Audio File
Encoded
Audio File
Encoded Audio File
available
Meld
WinMerge…
Step 1: Method returns a primitive type
Technical Solution: Approval Tests (string comparison)
Context: No side effect + Method returns a primitive type
Server 1
Remote Server 1
Audio File
download
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
Audio File Encoded
Audio File
Encoded
Audio File
Encoded Audio File
available
Note: encoding issues
Step 2: Branches coverage by input
parameters variation
Technical Solution: Approval Tests (legacyApprovals)
Context: No side effect + Method returns a primitive type
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
Audio File Encoded
Audio File
Encoded
Audio File
Encoded Audio File
available
Server 1
Remote Server 1
Audio File
download
Step 3: Method returns a complex type
Note: date issues
Context: No side effect + Method returns a complex type
Technical Solution: Approval Tests + XStream
Server 1
Remote Server 1
Audio File
download
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
Audio File Encoded
Audio File
Encoded
Audio File
Encoded Audio File
available
IFluxTmlg
IBodyTmlg
ITravelInfoTmlg
IAudioAnnounceTmlg
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
Audio File Encoded
Audio File
Encoded
Audio File
Encoded Audio File
available
Step 4: Third-party services
Context: WebService difficult to configure or/and not
avalaible
Technical Solution: Moco
Server 1
Remote Server 1
Audio File
download
Step 5: Capturing side effects
Note: can be used for context with void methods
not mocking side effect
Context: Side effects
Technical Solution: State, Side Effects Serialization + Approval
Tests
Server 1
Remote Server 1
Audio File
download
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
Audio File Encoded
Audio File
Encoded
Audio File
Encoded Audio File
available
Conclusion - Why it’s working?
Easy assertion: record and replay
Even ugly tests do the job (Temporary tests)
Fast to execute
Available good libraries:
Approval Tests, XStream, Moco…
Tests are resilient to refactoring
Next…
http://approvaltests.sourceforge.net/
http://martinsson-johan.blogspot.fr/
http://github.com/dreamhead/moco
https://github.com/pearlfish/pearlfish-java
UI visual diffing
https://www.youtube.com/watch?v=UMnZiTL0tUc
Working Effectively with Legacy Code – in particular for
creating “seams”
http://approvaltests.sourceforge.net/
http://approvaltests.sourceforge.net/
Approval Tests
only needs 2
lines!
http://approvaltests.sourceforge.net/
Run your test
Diff Tool (by default TortoiseMerge)
Cf. Using Reporters in Approval Tests
http://blog.approvaltests.com/2011/12/using-reporters-in-approval-tests.html
http://approvaltests.sourceforge.net/
Result of the current test
named received
http://approvaltests.sourceforge.net/
Result reference
named approved
http://approvaltests.sourceforge.net/
Approve result
and save file
http://approvaltests.sourceforge.net/
BACKUP
Server 1
Server 2
EncodeAudioLegacy Challenge
Remote Server 1
Audio File encoding
HTTPS Server 2
Audio File available
at Remote Server 1
download
Encode Audio Engine
upload
AudioAnnouceTmlg
URL Remote Server 1
format
filename
audioConfigTmp
target audio file extension
target encoding properties
httpConfigTmp
Local Tempory Folder path,
URL Remote HTTPS Server 2
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format

More Related Content

Viewers also liked

Main parts of the computer
Main parts of the computerMain parts of the computer
Main parts of the computerBastien David
 
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...Mozaic Works
 
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, BucharestSandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, BucharestMozaic Works
 
Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Peter Kofler
 
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...Mozaic Works
 
Simplifying your design with higher-order functions
Simplifying your design with higher-order functionsSimplifying your design with higher-order functions
Simplifying your design with higher-order functionsSamir Talwar
 
I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"Cyrille Martraire
 
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)Radu Marinescu
 

Viewers also liked (9)

Main parts of the computer
Main parts of the computerMain parts of the computer
Main parts of the computer
 
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
 
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, BucharestSandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
 
Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)
 
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
 
Simplifying your design with higher-order functions
Simplifying your design with higher-order functionsSimplifying your design with higher-order functions
Simplifying your design with higher-order functions
 
I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"
 
The Art of Creativity
The Art of CreativityThe Art of Creativity
The Art of Creativity
 
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
 

Recently uploaded

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Recently uploaded (20)

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 

100 % Confident With Legacy Code