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 Responses

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

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Other popular topics Top

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
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
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