Testing functions with side-effects

While we aim to write pure functions in our applications, this isn't always possible. In this section, we'll explore how to test functions that have side-effects. In most other programming languages, this is done by creating mocks that verify the correct side-effect is being produced. However, in Elixir, these kind of mocks are avoided as much as possible, since they typically rely on changing a certain module or function globally. This change makes us run our tests sequentially, which will increase the time to run them and hence make us less productive in the long run.

We will still explore how to create mocks in Elixir, but beware that they aren't used as often as in testing frameworks of other programming ...

Get Mastering 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.