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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.