SlideShare una empresa de Scribd logo
1 de 28
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/

Más contenido relacionado

Más de 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
 

Más de 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
 

Último

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 

Último (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 

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