Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Refactoring legacy code using Approval testing ...

Refactoring legacy code using Approval testing (Meetup Alicante)

Slides used during the Software Crafters Meetup session.
The session had two parts:
* An introduction and open discussion about concepts like legacy code and technical debt.
* A live-coding session to show a technique called "approval testing", applying it to cover with tests some "legacy code".

https://www.meetup.com/es-ES/Software-Crafters-Alicante/events/267849996/

Isidro López

January 22, 2020
Tweet

More Decks by Isidro López

Other Decks in Programming

Transcript

  1. Ego slide Hemos venido a jugar... Desarrollador de software/producto @islomar

    [email protected] <titulitis> Teleco, Antropología Social y Cultural, Executive MBA, CSM… </titulitis>
  2. For some people, legacy code is about... • Code not

    developed by me • Code that you don't know • Code without tests • Code difficult to maintain (difficult to understand or change) • Code no longer supported • Code that you would prefer not to touch • ?
  3. Debt metaphor by Ward Cunningham (1992) “Shipping first time code

    is like going into debt. A little debt speeds development so long as it is paid back promptly with a rewrite. [...] The danger occurs when the debt is not repaid.”
  4. About technical debt • The extra effort that it takes

    to keep on working on the code is the interest paid on the debt. • It slows you down in baby steps, not realizing and taking for granted that “it is the way it is”. • OK in isolated and stable areas which are “never” touched.
  5. How to refactor (complex) legacy code? • We do not

    have tests as safety net before starting to refactor! • But… what if it is not really clear what is the current behavior?
  6. Approval testing to the rescue!! It also exists something called

    Golden Master "Approval testing is a test technique which compares the current output of your code with an "approved" version. The approved version is created by initially examining the test output and approving the result." Assume the current behaviour is correct: the first goal is to refactor in a safe way!!
  7. Resources: kata and approval testing • Kata ◦ Description of

    the kata ◦ https://github.com/emilybache/GildedRose-Refactoring-Kata ◦ https://github.com/emilybache/GildedRose-Approval-Kata ◦ http://coding-is-like-cooking.info/2013/03/writing-good-tests-for-the-gilded -rose-kata/ • Approval testing ◦ https://www.infoq.com/news/2017/02/approval-testing-texttest ◦ http://approvaltests.com/
  8. Resources: screencasts and books • Screencasts ◦ Refactoring legacy code

    with approval testing (Emily Bache) ◦ Approval tests with Lift Kata (Emily Bache) ◦ Testing and refactoring legacy code (Sandro Mancuso) ◦ Approval tests with Java • Emily Bache ◦ https://www.praqma.com/stories/all/#emilybache ◦ https://github.com/emilybache ◦ How to develop new features with approval testing
  9. Resources: refactoring and technical debt • Original writing about technical

    debt from Ward Cunningham ◦ The Debt Metaphor (video) • Tech Debt - MPJ's Musings - Fun Fun Function • https://martinfowler.com/bliki/TechnicalDebt.html • https://martinfowler.com/bliki/TechnicalDebtQuadrant.html • https://www.fluentcpp.com/2020/01/17/technical-debt-is-like-a-tetris-game/ • https://martinfowler.com/bliki/DesignPayoffLine.html • https://martinfowler.com/bliki/DesignStaminaHypothesis.html • https://martinfowler.com/articles/workflowsOfRefactoring/ • https://www.praqma.com/stories/advanced-testing-refactoring-techniques/