How I deal with behaviours and boilerplate
This post was originally published on the BetterDoc Dev-Blog.
For a while now I’ve been a big fan of using the Elixir library
mox for creating test mocks.
mox you define behaviours as basis for your mocks.
You can think of behaviours as interfaces in object oriented languages such as Java: a set of function signatures that a module has to implement.
While this approach is great - check out this blog post on the why - it tends to require a bit of boilerplate code. In this post we are going to explore how I use behaviours for mocking, the reasoning behind it, and how I reduce the necessary boilerplate to an absolute minimum by using metaprogramming.