Reputation: 8988
I know you can debug the webapp with IEx but is it possible to set a breakpoint inside a test?
For example in the following test I would like to check what's inside conn or check any other variable or macro.
defmodule HelloWeb.PageControllerTest do
use HelloWeb.ConnCase
require IEx
test "GET /", %{conn: conn} do
IEx.pry
conn = get conn, "/"
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end
In order to make it work with the webapp you must have phoenix.server running with iex -S mix phoenix.server
But in this case is a test not the webapp so it complains with:
Cannot pry #PID<0.406.0> at ... Is an IEx shell running?
Upvotes: 3
Views: 1662
Reputation: 1155
To check what is inside conn structure (or any other variable) you can just use IO.inspect conn
and run tests as usual with mix test
- there is no need to use pry here. For example:
defmodule HelloWeb.PageControllerTest do
use HelloWeb.ConnCase
test "GET /", %{conn: conn} do
IO.inspect conn, limit: :infinity
conn = get conn, "/"
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end
However, if you really need a shell you can then call it like this:
iex -S mix test
Upvotes: 7
Reputation: 241
ExUnit tests are in .exs files that mean interpreted code is written in it. So you can't set break point in it.
For more informations about .exs and .ex file. See Elixir: When to use .ex and when .exs files
If you want to check any map simply write
IO.inspect conn
And for simple variable you can write
IO.puts variable_name
Upvotes: 2