SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
Refactorer legacy, même
pas peur!
Johan MARTINSSON
Développeur - Indépendant
martinsson.johan@gmail.co
m
@johan_alps
Rémy SANLAVILLE
Développeur - 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% Legacy Code Coverage with Golden
Master2014
Anonymous Developers - Season 2
Le problème – dans le legacy
Long d’écrire les tests
Les tests haut niveau sont longs à éxécuter
Les tests unitiare adhèrent au code
Working with Legacy Code
100% Legacy Code Coverage with Golden
Master2014
Anonymous Developers - Season 2
Working with Legacy Code
Don’t forget to replace
tempory refactoring
tests
by maintainable 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
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
propertieshttpConfigTmp
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
Baby Steps
String comparison with ApprovalTests
Branch coverage by input parameter variation
Serializing a complex type
Mocking web services
Capturing side effects
Step 0: Development environment validation
EclEmmaJUnit
Technical Solution: Unit Testing + Code Coverage Tools
Context: Launch UT + Code Coverage
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
AudioAnnouceTmlg
URL Remote
Server 1
format
filename
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format
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
AudioAnnouceTmlg
URL Remote
Server 1
format
filename
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format
Step 2: Branch coverage by input
parameter variation
Technical Solution: Approval Tests (legacyApprovals)
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
AudioAnnouceTmlg
URL Remote
Server 1
format
filename
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format
Step 3: Method returns a complex type
Note: encoding + 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
AudioAnnouceTmlg
URL Remote
Server 1
format
filename
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format
Step 4: Third-party services
Context: WebService difficult to configure or/and not
avalaible
Technical Solution: Moco
Server 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
AudioAnnouceTmlg
URL Remote
Server 1
format
filename
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format
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 2
encoding
HTTPS Server 2
Audio File available
at Remote Server 1
Encode Audio Engine
upload
AudioAnnouceTmlg
URL Remote
Server 1
format
filename
Local Tempory Folder
Audio File Encoded
Audio File
Local HTTP
Server
Encoded
Audio File
Encoded Audio File
available
AudioFile
name
format
Server 1
Remote Server 1
Audio File
download
Pourquoi ça marche?
Pas de rédaction d’assertion
Pas d’effort lié à la maintenance
De bons outils
Tests taillés pour le refactoring
Conclusion
http://approvaltests.sourceforge.net/
Ensuite
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/
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/

Weitere ähnliche Inhalte

Mehr von martinsson

Split my monolith - Workshop
Split my monolith - WorkshopSplit my monolith - Workshop
Split my monolith - Workshopmartinsson
 
TDD de la vraie vie - AlpesCraft 2022
TDD de la vraie vie - AlpesCraft 2022TDD de la vraie vie - AlpesCraft 2022
TDD de la vraie vie - AlpesCraft 2022martinsson
 
Testing strategies
Testing strategiesTesting strategies
Testing strategiesmartinsson
 
Testing strategies visualized
Testing strategies visualizedTesting strategies visualized
Testing strategies visualizedmartinsson
 
Split my monolith! Workshop
Split my monolith! Workshop Split my monolith! Workshop
Split my monolith! Workshop martinsson
 
No Agility without Continuous Delivery
No Agility without Continuous DeliveryNo Agility without Continuous Delivery
No Agility without Continuous Deliverymartinsson
 
No agility without continuous delivery frugagile
No agility without continuous delivery   frugagileNo agility without continuous delivery   frugagile
No agility without continuous delivery frugagilemartinsson
 
De legacy au tdd agilegrenoble
De legacy au tdd   agilegrenobleDe legacy au tdd   agilegrenoble
De legacy au tdd agilegrenoblemartinsson
 
De legacy au tdd - Agile pays basque
De legacy au tdd  - Agile pays basqueDe legacy au tdd  - Agile pays basque
De legacy au tdd - Agile pays basquemartinsson
 
Usable software design ncraft
Usable software design ncraftUsable software design ncraft
Usable software design ncraftmartinsson
 
Usable software design - code utilisable
Usable software design - code utilisableUsable software design - code utilisable
Usable software design - code utilisablemartinsson
 
Pyramide des tests
Pyramide des testsPyramide des tests
Pyramide des testsmartinsson
 
Changer Pour Mieux Coder
Changer Pour Mieux CoderChanger Pour Mieux Coder
Changer Pour Mieux Codermartinsson
 

Mehr von martinsson (15)

Split my monolith - Workshop
Split my monolith - WorkshopSplit my monolith - Workshop
Split my monolith - Workshop
 
TDD de la vraie vie - AlpesCraft 2022
TDD de la vraie vie - AlpesCraft 2022TDD de la vraie vie - AlpesCraft 2022
TDD de la vraie vie - AlpesCraft 2022
 
Testing strategies
Testing strategiesTesting strategies
Testing strategies
 
Testing strategies visualized
Testing strategies visualizedTesting strategies visualized
Testing strategies visualized
 
Split my monolith! Workshop
Split my monolith! Workshop Split my monolith! Workshop
Split my monolith! Workshop
 
No Agility without Continuous Delivery
No Agility without Continuous DeliveryNo Agility without Continuous Delivery
No Agility without Continuous Delivery
 
No agility without continuous delivery frugagile
No agility without continuous delivery   frugagileNo agility without continuous delivery   frugagile
No agility without continuous delivery frugagile
 
De legacy au tdd agilegrenoble
De legacy au tdd   agilegrenobleDe legacy au tdd   agilegrenoble
De legacy au tdd agilegrenoble
 
De legacy au tdd - Agile pays basque
De legacy au tdd  - Agile pays basqueDe legacy au tdd  - Agile pays basque
De legacy au tdd - Agile pays basque
 
Usable software design ncraft
Usable software design ncraftUsable software design ncraft
Usable software design ncraft
 
Usable software design - code utilisable
Usable software design - code utilisableUsable software design - code utilisable
Usable software design - code utilisable
 
Pyramide des tests
Pyramide des testsPyramide des tests
Pyramide des tests
 
Changer Pour Mieux Coder
Changer Pour Mieux CoderChanger Pour Mieux Coder
Changer Pour Mieux Coder
 
Mikado
MikadoMikado
Mikado
 
Mikado
MikadoMikado
Mikado
 

Kürzlich hochgeladen

Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Juan Carlos Gonzalez
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5DianaGray10
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 

Kürzlich hochgeladen (20)

Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 

Refactorer du legacy, même pas peur! Agile France