febeling

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

idi527

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

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”.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement