How to debug ExUnit tests with :debugger?

I meant something like

:debugger.start()
:int.ni(DebugTest)
:int.break(DebugTest, 16) # needs to be an executable line http://erlang.org/doc/apps/debugger/debugger_chapter.html#breakpoints
# or use http://erlang.org/doc/man/int.html#break_in-3
# :int.break_in(DebugTest, :hello, 0)

defmodule DebugTestTest do
  use ExUnit.Case
  doctest DebugTest

  test "greets the world" do
    result = DebugTest.hello()
    assert result == :world
  end
end

and then mix test --trace.


If you only want to “look around” in the test block, I think it’d be a bit simpler with IEx.pry

defmodule DebugTestTest do
  use ExUnit.Case
  doctest DebugTest
  require IEx

  test "greets the world" do
    result = DebugTest.hello()
    IEx.pry()
    assert result == :world
  end
end

and then iex -S mix test --trace.

5 Likes