Strategy - Slice

For when ‘Peel’ strategy doesn’t work, like when the difficult-to-test code is in the middle of the testable code, not at the beginning or end.

Session Outline

Connect - identify testability problems

Copy a symbol next to the items on this list which might make a function difficult to test:

Concept: Slice

This picture visualizes the Slice strategy: Slice

The function you’re trying to test has a line that is difficult to test in the middle. You can’t easily use Peel to remove it. You need to slice away the depencency and replace the hard to test call with a call to a stub or a fake.

Concrete: Slice

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

Reflect - when to Peel, when to Slice

What is important to remember when you add tests to code containing a call to a difficult-to-test function?