Peel

Emily Bache first learned this refactoring from Llewellyn Falco.

Examine

Look for a long function that you want to get under test, which includes a statement or short paragraph that makes it hard to test. Usually it refers to a dependency you don’t want to include in your unit test. If you can easily slide this function to the start or the end of the function then use Peel. Otherwise, try Slice.

Prepare

Isolate the smallest possible part that you want to be able to peel out of this function. This part will not be included in a subsequent unit test, so you want to make it as little logic as possible. You might want to extract a variable so it’s separated from the surrounding code.

Implement

Clear

Check the new function name is suitable and the visibility makes it possible to unit test.

Follow up

Prompted by Code Smells

Relevant Learning Hours

Sources

Back to All Refactorings