CheckOps
Mox
Mox is an Apache-2.0 Elixir library from Dashbit for defining concurrent, behaviour-based mocks that follow the "mocks as explicit contracts" principles and work with async tests.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Mox is a library for defining concurrent mocks in Elixir, created by José Valim’s company Dashbit. It follows the principles from the article “Mocks and explicit contracts”: no ad-hoc mocks (mocks are only created from behaviours), no dynamic module generation during tests, concurrency support so tests using the same mock can still run with async: true, and reliance on pattern matching and function clauses for asserting inputs rather than complex expectation rules.
You define a mock for a behaviour with Mox.defmock(MyApp.MockWeather, for: MyApp.WeatherAPI) in test_helper.exs, configure your application to use the mock in tests, then set expectations with expect(MockWeather, :temp, fn {lat, lon} -> {:ok, 30} end) or stubs with stub/3. verify_on_exit! checks that expectations were met. Because expectations are scoped to the test process (with explicit allowances or global mode for other processes), concurrent tests do not interfere. The goal, per the README, is to help you define contracts between parts of your application.
The source code is at dashbitco/mox on GitHub under the Apache-2.0 licence, with about 1,400 stars; the most recent commit was on 7 November 2026.
Features
- Behaviour-based: Mocks only for explicit contracts.
- Async-safe: Process-scoped expectations work with
async: true. - Pattern matching: Assert inputs with function clauses.
- Verification:
verify_on_exit!ensures expectations ran.
Pros
- Free to use: Open source under the Apache-2.0 licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 7 November 2026.
Cons
- Requires behaviours: Code must depend on behaviours and configurable modules.
- Process allowances: Mocks used in other processes need explicit allowances.
Usage and Links (Example)
# test/test_helper.exs
Mox.defmock(Shop.MockPayments, for: Shop.Payments)
Application.put_env(:shop, :payments, Shop.MockPayments)
# test/checkout_test.exs
defmodule Shop.CheckoutTest do
use ExUnit.Case, async: true
import Mox
setup :verify_on_exit!
test "charges the total" do
expect(Shop.MockPayments, :charge, fn 100 -> {:ok, "tx-1"} end)
assert {:ok, "tx-1"} = Shop.Checkout.pay(100)
end
end
Resources:
Pricing
Mox is free and open source under the Apache-2.0 licence.
Recommended for?
- Elixir teams mocking external services behind behaviours.
- Projects with async test suites.
Conclusion
Mox is the idiomatic Elixir mocking library, encouraging explicit contracts while keeping tests concurrent.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Mox side by side.
EExUnitExUnit is Elixir's built-in unit testing framework, with concurrent async tests, describe blocks, setup callbacks, tags, doctests and rich assertion diffs, run with mix test.Compare with Mox
SStreamDataStreamData is an Apache-2.0 Elixir library for data generation and property-based testing, with composable generators, shrinking and ExUnit integration.Compare with Mox
WWallabyWallaby is an MIT-licensed Elixir library for browser-based feature tests of web applications, simulating realistic user interactions, running tests concurrently and managing browsers via ChromeDriver or Selenium.Compare with Mox
MMockallMockall is a powerful mock object library for Rust, generating mocks for traits and structs with the #[automock] attribute or mock! macro, with expectations, predicates and call counts.Compare with Mox
GGoMock (uber-go/mock)GoMock is an Apache-2.0 mocking framework for Go, maintained by Uber after the original golang/mock was archived, with the mockgen code generator and a gomock controller for expectations.Compare with Mox
MMockKMockK is an Apache-2.0 mocking library built for Kotlin, supporting final classes, objects, coroutines, extension functions and top-level functions with a concise DSL.Compare with Mox