Peel - a strategy for difficult to test code

This strategy is useful when you have code that is easy to test sandwiched in the middle of hard-to-test code.

Session Outline

Connect - recap Extract Function

These are some steps you can follow in a ‘extract function’ refactoring. What order should you do the steps in? Re-order them in your own copy of the list.

  1. Compile and run tests
  2. Declare a new function with a suitable name
  3. Define the return type of the new function
  4. Identify the section of code you want to extract and copy it
  5. Replace the section of code with a call to the new function
  6. Define the arguments of the new function
  7. Compile
  8. Paste the section of code as the body of the new function
  9. Compile and run tests

Concept: Peel

This picture visualizes the Peel strategy: Peel

The function you’re trying to test begins and/or ends with a line that is difficult to test. You want to peel that part away to get to the testable middle. Use an ‘Extract Function’

Concrete: Peel

One way to solve TirePressure is using Peel. You can also do it on ‘getScore’ in IceCreamScores

Reflect - when to Peel

When should you use the ‘peel’ strategy? Are there any disadvantages to using it?