CheckOps
ExUnit
ExUnit 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.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
ExUnit is the unit testing framework that ships with Elixir. Every Mix project is generated with a test/ directory and test_helper.exs that calls ExUnit.start(), and mix test runs the suite. Because it is part of the language distribution, all Elixir libraries and Phoenix applications share the same testing conventions.
Test modules use ExUnit.Case and define tests with the test macro, grouped with describe. Passing async: true runs a module’s tests concurrently with other async modules, taking advantage of the BEAM’s lightweight processes. The assert macro inspects the expression to produce detailed failure diffs, and assert_receive, assert_raise and pattern-matching assertions fit Elixir’s style. setup and setup_all callbacks build context, tags (@tag :slow) filter runs, and doctest MyModule runs examples from documentation. mix test --failed, --stale and --cover support fast feedback and coverage. Elixir is Apache-2.0 licensed.
ExUnit also supports capturing logs and IO (ExUnit.CaptureLog, ExUnit.CaptureIO), per-test timeouts, and seeds for reproducing random test order, and Phoenix builds its ConnCase and DataCase helpers on top of ExUnit’s case templates.
Features
- Built into Elixir: Standard across all Mix projects.
- Concurrent tests:
async: trueruns modules in parallel. - Doctests: Run documentation examples as tests.
- Helpful diffs: Rich assertion failure output.
Pros
- Free: Included with Elixir.
- Concurrent by design: Takes advantage of BEAM processes.
Cons
- Shared state care: Async tests must avoid shared global state (for example, use the Ecto SQL sandbox).
- Limited built-in mocking: Use Mox for behaviour-based mocks.
Usage and Links (Example)
defmodule Shop.PricingTest do
use ExUnit.Case, async: true
doctest Shop.Pricing
describe "apply/2" do
test "applies a discount" do
assert Shop.Pricing.apply(100, 10) == 90
end
test "rejects negative prices" do
assert_raise ArgumentError, fn -> Shop.Pricing.apply(-1, 0) end
end
end
end
mix test --cover
mix test --failed
Resources:
Pricing
Free as part of Elixir (Apache-2.0 licence).
Recommended for?
- Every Elixir and Phoenix project.
- Teams wanting fast, concurrent test suites on the BEAM.
Conclusion
ExUnit is a capable, concurrent and well-integrated test framework that makes testing a first-class part of Elixir.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with ExUnit side by side.
MMoxMox 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.Compare with ExUnit
SStreamDataStreamData is an Apache-2.0 Elixir library for data generation and property-based testing, with composable generators, shrinking and ExUnit integration.Compare with ExUnit
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 ExUnit- Ppytestpytest is the usual Python test runner: plain asserts, fixtures, parametrization, and a large plugin set.Compare with ExUnit
RRSpecRSpec is the MIT-licensed behaviour-driven testing framework for Ruby, made up of rspec-core, rspec-expectations and rspec-mocks, and widely used with Rails via rspec-rails.Compare with ExUnit
MMinitestMinitest is an MIT-licensed, fast and lightweight Ruby testing library providing xUnit-style tests, a spec DSL and benchmarks; it is the default testing framework in Ruby on Rails.Compare with ExUnit