Fl4m3Ph03n1x
Background
I have a small function with some branching logic and I have some tests for it. I would like to use the erlang debugger when I run a given test to make sure I am executing the correct code.
Code
Lets assume we are testing DebuggerTest.greet/1:
defmodule DebugerTest do
def greet(greeting) do
if greeting == "Hola" do
str = "#{greeting} mundo!"
IO.puts(str)
:spanish_greet
else
str = "#{greeting} world!"
IO.puts(str)
:normal_greet
end
end
end
Now, this function has some branching logic, and the code is overall horrible, but it does give us a lot of juicy executable lines that we attach a breakpoint to.
These are the tests I am running:
defmodule DebugerTestTest do
use ExUnit.Case
doctest DebugerTest
test "greets the world" do
assert DebugerTest.greet("Hello") == :normal_greet
end
test "greets the world in spanish" do
assert DebugerTest.greet("Hola") == :fail_greet
end
end
As you can see, my spanish greeting test will fail. However, I want to find that out using the erlang debugger:
Running the tests
Given that I am only interested in running the failing test, I change my code to:
@tag :wip
test "greets the world in spanish" do
assert DebugerTest.greet("Hola") == :fail_greet
end
And then I run mix test --only wip.
There, now I am running only the failing test. But I am still not using the debugger.
To try to fix this I tried running the tests via an iex shell iex -S mix test --only wip but the run is automated and it ends before I can setup the debugger:
:debugger.start()
:int.ni(DebugerTest)
:int.break(DebugerTest, 3)
Question
How can I run the erlang debugger when using mix test ?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
stefanchrobot
Try
iex -S mix test --trace --only wip.Fl4m3Ph03n1x
Doesnt work:
stefanchrobot
Seems to be working for me:
and then:
waits for the debugger to finish.
lukaszsamson
ElixirLS VSCode extension supports running tests with debugging right from the UI. Navigate to Testing tab and click Debug test or right click an icon next to test definition and select Debug test.