ExUnit. It's an app!

Notes

I imagine many think ExUnit just does some scripting to run tests. But it’s a full Elixir app!

I love to see how Elixir’s built-in tools work. So, let’s check it out.

If you take a look at your test/test_helper.exs, you’ll notice we call ExUnit.start() to start an Elixir app.

If you dive into the source code, you’ll find a supervisor with three children (as of version 1.15).

  def start(_type, []) do
    children = [
      ExUnit.Server,
      ExUnit.CaptureServer,
      ExUnit.OnExitHandler
    ]

    opts = [strategy: :one_for_one, name: ExUnit.Supervisor]
    Supervisor.start_link(children, opts)
  end

We can see that same supervision tree by launching our observer from iex in our test environment.

To do that, let’s run our tests in the context of iex with iex -S mix test. Then launch the observer with :observer.start().

Want the latest Elixir Streams in your inbox?

    No spam. Unsubscribe any time.