Slide 1

Slide 1 text

Refactoring legacy code using approval testing CSAT Lunch & Learn, 01.02.2019 @islomar

Slide 2

Slide 2 text

What is legacy code for you?

Slide 3

Slide 3 text

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 ● ?

Slide 4

Slide 4 text

What is technical debt for you?

Slide 5

Slide 5 text

Is technical debt always "bad"?

Slide 6

Slide 6 text

Technical Debt Quadrant https://martinfowler.com/bliki/TechnicalDebtQuadrant.html

Slide 7

Slide 7 text

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!

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Gilded Rose refactoring kata Description of the kata https://github.com/emilybache/GildedRose-Refactoring-Kata https://github.com/emilybache/GildedRose-Approval-Kata https://github.com/islomar/approval-testing http://approvaltests.com/

Slide 11

Slide 11 text

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 e-kata/ ● https://martinfowler.com/bliki/TechnicalDebt.html ● https://martinfowler.com/bliki/TechnicalDebtQuadrant.html

Slide 12

Slide 12 text

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)

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Thanks for the feedback!! https://islomar.typeform.com/to/Jqkh8l

Slide 16

Slide 16 text

No content