Refactorer legacy, même
pas peur!
Johan MARTINSSON
Développeur - Indépendant
martinsson.johan@gmail.co
m
@johan_alps
Rémy ...
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ère...
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://...
Trivia Challenge
https://github.com/jbrains/trivia
http://www.hasbro.com/games/en_US/shop/details.cfm?R=93C6EE71-
6D40-101...
Server 1
Server 2
EncodeAudioLegacy Challenge
Remote Server 1
Audio File encoding
HTTPS Server 2
Audio File Encoded
Audio ...
Server 1
Server 2
EncodeAudioLegacy Challenge
Remote Server 1
Audio File encoding
HTTPS Server 2
Audio File available
at R...
Baby Steps
String comparison with ApprovalTests
Branch coverage by input parameter variation
Serializing a complex type
Mo...
Step 0: Development environment validation
EclEmmaJUnit
Technical Solution: Unit Testing + Code Coverage Tools
Context: La...
Step 1: Method returns a primitive type
Technical Solution: Approval Tests (string comparison)
Context: No side effect + M...
Step 2: Branch coverage by input
parameter variation
Technical Solution: Approval Tests (legacyApprovals)
Context: No side...
Step 3: Method returns a complex type
Note: encoding + date issues
Context: No side effect + Method returns a complex type...
Step 4: Third-party services
Context: WebService difficult to configure or/and not
avalaible
Technical Solution: Moco
Serv...
Step 5: Capturing side effects
Note: can be used for context with void methods
not mocking side effect
Context: Side effec...
Pourquoi ça marche?
Pas de rédaction d’assertion
Pas d’effort lié à la maintenance
De bons outils
Tests taillés pour le re...
Conclusion
http://approvaltests.sourceforge.net/
Ensuite
http://approvaltests.sourceforge.net/
http://martinsson-johan.blogspot.fr/
http://github.com/dreamhead/moco
https:...
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 T...
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/
Prochain SlideShare
Chargement dans…5
×

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

4 970 vues

Publié le

tldr; L’approche classique des tests n’est pas adapté pour le refactoring dans le legacy. Il vaut mieux écrire des tests automatiques jetables. Du fait qu’il y ait 0 besoin de maintenance et avec l’outillage adapté cela est très TRES rapide (ex 200 lignes en 5min).

http://martinsson-johan.blogspot.fr/2014/05/refactorer-legacy-meme-pas-peur.html

https://www.youtube.com/watch?v=qEPb7eqvxes

Publié dans : Technologie
0 commentaire
0 j’aime
Statistiques
Remarques
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Aucun téléchargement
Vues
Nombre de vues
4 970
Sur SlideShare
0
Issues des intégrations
0
Intégrations
3 192
Actions
Partages
0
Téléchargements
4
Commentaires
0
J’aime
0
Intégrations 0
Aucune incorporation

Aucune remarque pour cette diapositive

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

  1. 1. 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
  2. 2. Working with Legacy Code
  3. 3. Working with Legacy Code Refactoring Legacy Code with Object Calisthenics2012 - 2013 Anonymous Developers - Season 1
  4. 4. Working with Legacy Code 100% Legacy Code Coverage with Golden Master2014 Anonymous Developers - Season 2
  5. 5. 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
  6. 6. Working with Legacy Code 100% Legacy Code Coverage with Golden Master2014 Anonymous Developers - Season 2
  7. 7. Working with Legacy Code Don’t forget to replace tempory refactoring tests by maintainable tests
  8. 8. 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 ?
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. Baby Steps String comparison with ApprovalTests Branch coverage by input parameter variation Serializing a complex type Mocking web services Capturing side effects
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. 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
  19. 19. Pourquoi ça marche? Pas de rédaction d’assertion Pas d’effort lié à la maintenance De bons outils Tests taillés pour le refactoring
  20. 20. Conclusion
  21. 21. http://approvaltests.sourceforge.net/
  22. 22. 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”
  23. 23. http://approvaltests.sourceforge.net/ Approval Tests only needs 2 lines!
  24. 24. 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
  25. 25. http://approvaltests.sourceforge.net/ Result of the current test named received
  26. 26. http://approvaltests.sourceforge.net/ Result reference named approved
  27. 27. http://approvaltests.sourceforge.net/ Approve result and save file
  28. 28. http://approvaltests.sourceforge.net/

×