Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.62 KB

step-by-step.md

File metadata and controls

40 lines (32 loc) · 1.62 KB

Day 23: Refactor the legacy code after putting it under test.

Refactor the TripService class to ensure Clean Code / SOLID principles

Legacy code golden rules : You cannot change any existing code if not covered by tests.

The only exception is if we need to change the code to add unit tests, but in this case, just automated refactorings (via IDE) are allowed.

Tips

  • Start testing from shortest to deepest branch
  • Start refactoring from deepest to shortest branch

Working with Legacy Code Tips

Step by Step

  1. Cover the production code
  2. Improve confidence in our tests
  3. Refactor the production code
  4. Other refactorings

What did we use / learn ?

  • Seams
  • Automated refactoring via our IDE
    • Extract Method
    • Change Signature
    • Rename
  • Mutation Testing
  • Use Higher Order Functions to avoid duplication
  • Use code coverage as a driver
  • Test Data Builder
  • Feature Envy
  • Sprout Class
  • TDD

Sources :

Sandro's video