Skip to content

orient-man/TripServiceKata

Repository files navigation

Testing and Refactoring Legacy Code

.NET version of Sandro Mancuso refactoring kata (see links).

Code

git clone https://github.com/orient-man/TripServiceKata.git
cd TripServiceKata
git checkout demo-start

Navigating refactoring steps with git

Useful git aliases:

prev = checkout HEAD^1
next = "!git checkout `git rev-list HEAD..demo-end | tail -1`"
goto = "!f() { git reset --hard && git clean -fd && git checkout $1; }; f"

Context

Imagine a social networking website for travelers

  • You need to be logged in to see the content
  • You need to be a friend to see someone else's trips

Legacy Code Rules

  • You cannot change production code if not covered by tests
  • Just automated ("safe") refactorings (via IDE) are allowed, if needed to write the test

Testing tips

Start testing from shortest do deepest branch

  • because getting to deepest requires big setup i.e. sample data, mocks, fakes etc.)
  • allows to understand better what the code does

Refactoring tips

Starting from the deepest branch to the shortest (different than testing)

  • method does too much (feature envy)
  • Single Responsibility Principle!

Craftsmen at work

  • Write readable and maintainable code
  • code must express business rules
  • Strive for simplicity
  • Know your tools well (i.e. frameworks, editor)
  • Work in small and safe increments
  • commit often
  • Embrace change, be brave
  • Boy scout rule / No broken windows

Links

About

.NET version of Sandro Mancuso refactoring kata

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages