SlideShare une entreprise Scribd logo
1  sur  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/

Contenu connexe

Plus 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
 

Plus 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
 

Dernier

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
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
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
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
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

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