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 full-size slide

  2. What is legacy code for you?

    View full-size 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 full-size slide

  4. What is technical debt for you?

    View full-size slide

  5. Is technical debt always "bad"?

    View full-size slide

  6. Technical Debt Quadrant

    View full-size 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 full-size 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 full-size slide

  9. Gilded Rose refactoring kata
    Description of the kata

    View full-size slide

  10. 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 full-size slide

  11. 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 full-size slide

  12. Thanks for the feedback!!

    View full-size slide