Refactoring Toward Pure Functions

When you have a module that’s really hard to test, refactoring as much of the logic into pure functions is the easiest way to simplify testing, if you can make it work. We’ll deep dive into an example of this in the GenServer section of Chapter 3, Testing OTP, but let’s make sure we understand the basic ideas before we move on. When code has an external dependency, it rarely acts as a straight pass-through of the values of that dependency. Most of the time, it will make a call to a dependency and then manipulate the response before returning the result of the function call. The more manipulation your code does of that data, the better a candidate it is for refactoring the logic into a pure function.

Let’s ...

Get Testing Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.