我知道您可以使用 IEx 调试 webapp,但是是否可以在测试中设置断点?
例如,在下面的测试中,我想检查 conn 中的内容或检查任何其他变量或宏。
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
为了让它与 webapp 一起工作,你必须让 phoenix.server 运行 iex -S mix phoenix.server
但在这种情况下是一个测试而不是 webapp 所以它提示:
Cannot pry #PID<0.406.0> at ... Is an IEx shell running?
最佳答案
要检查 conn 结构(或任何其他变量)中的内容,您只需使用 IO.inspect conn
并像往常一样使用 mix test
运行测试 - 没有这里需要用到pry。例如:
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
但是,如果你真的需要一个 shell,你可以这样调用它:
iex -S mix test
关于testing - 使用 IEx 调试 phoenix 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47262653/