Is this a better way to test Elixir?

Mox lets you do concurrent testing. Each expect is bound to the lifetime of the test, and processes can figure out which test they map to to get where they need to go.

Instead of passing modules around, a better choice is to assign the module to a module attribute so it will be set at compiletime. This is extremely unobtrusive and basically replaces Modulename for @modulename. If you need to use a default impl aways except for when an expect is explicit, you can use stub_with to set it.

If you are wondering about the mechanics of how concurrency works with mox, here:

4 Likes