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

Refactoring legacy code using Approval testing

Refactoring legacy code using Approval testing

Presentation to support a talk and live coding session facilitated in Spotify.

With an introduction to reflect together about what legacy code or technical debt are, there was a live coding demo based on the Gilded Rose kata, in order to cover it with tests using the "approval testing" tools.

Isidro López

February 01, 2019

More Decks by Isidro López

Other Decks in Programming


  1. Refactoring legacy code using
    approval testing
    CSAT Lunch & Learn, 01.02.2019

    View Slide

  2. What is legacy code for you?

    View Slide

  3. 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


    View Slide

  4. What is technical debt for you?

    View Slide

  5. Is technical debt always "bad"?

    View Slide

  6. Technical Debt Quadrant

    View Slide

  7. How to refactor (complex) legacy code?

    But… what if it is not really clear what is the current behavior?

    We do not have tests as safety net before starting to refactor!

    View Slide

  8. 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!!

    View Slide

  9. View Slide

  10. Gilded Rose refactoring kata
    Description of the kata

    View Slide

  11. Interesting resources
    ● https://www.praqma.com/stories/advanced-testing-refactoring-techniques/
    ● https://www.infoq.com/news/2017/02/approval-testing-texttest
    ● http://coding-is-like-cooking.info/2013/03/writing-good-tests-for-the-gilded-ros
    ● https://martinfowler.com/bliki/TechnicalDebt.html
    ● https://martinfowler.com/bliki/TechnicalDebtQuadrant.html

    View Slide

  12. Interesting resources
    ● Screencasts
    ○ Screencast: refactoring legacy code with approval testing (Emily Bache)
    ○ Screencast: testing and refactoring legacy code (Sandro Mancuso)
    ○ Approval tests with Java
    ● Books
    ○ https://www.goodreads.com/book/show/44936.Refactoring
    ○ Working effectively with legacy code (Michael Feathers)

    View Slide

  13. View Slide

  14. View Slide

  15. Thanks for the feedback!!

    View Slide

  16. View Slide