febeling
How to debug ExUnit tests with :debugger?
I have the idea to use the (Erlang) debugger to debug my Elixir tests, using breakpoints set via the UI and stepping through code by line or expression. I also want to avoid littering the code with Pry or breakpoint statements. Is that something that’s possible?
I searched docs and more broadly, but I didn’t find a conclusive answer yet.
My understanding for now is, that the debugger needs to be started from the iex repl, but there doesn’t seem to be reliable way to run tests from there.
Most Liked Responses
idi527
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.
idi527
Yeah, there is no way to “step through” with IEx.pry. I still use it, yes, usually right before the assert macros to have a “look around”.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #podcasts
- #code-sync
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








