CheckOps home

Tools directory

E

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Built into Elixir: Standard across all Mix projects.
  2. Concurrent tests: async: true runs modules in parallel.
  3. Doctests: Run documentation examples as tests.
  4. Helpful diffs: Rich assertion failure output.

Pros

  1. Free: Included with Elixir.
  2. Concurrent by design: Takes advantage of BEAM processes.

Cons

  1. Shared state care: Async tests must avoid shared global state (for example, use the Ecto SQL sandbox).
  2. Limited built-in mocking: Use Mox for behaviour-based mocks.
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).

  1. Every Elixir and Phoenix project.
  2. 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.