Refactoring great habits


#1

Considerations when writing a new test

  • Tests should test one thing only.
  • Create more specific tests to drive a more generic solution (triangulate).
  • Give your tests meaningful names (behavior/goal-oriented) that reflect your business domain.
  • See the test fail for the right reason.
  • Ensure you have meaningful feedback from failing tests.
  • Keep your tests and production code separate.
  • Organize your unit tests to reflect your production code (similar project structure).
  • Organize your test in arrange, act and assert blocks.
  • Write the assertion first and work backward.
  • Write fast, isolated, repeatable and self-validating tests.

Considerations when making a failing test pass

  • Write the simplest code to pass the test.
  • Write any code that makes you get to the refactor phase quicker.
  • Use Transformation Priority Premise.
  • Consider using object calisthenics to drive design decisions.

Considerations after the test passes

  • Use the Rule of Three to tackle duplication.
  • Refactor design constantly.
  • Apply object calisthenics to improve your design.
  • Stay on the green while refactoring (New habit).
  • Use the IDE to refactor quickly and safely (New habit).
  • Refactor code for readability/understandability first (New habit).