Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 使用IEx调试phoenix测试_Testing_Elixir_Phoenix Framework - Fatal编程技术网

Testing 使用IEx调试phoenix测试

Testing 使用IEx调试phoenix测试,testing,elixir,phoenix-framework,Testing,Elixir,Phoenix Framework,我知道你可以用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

我知道你可以用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?
无法在以下位置撬动PID#。。。IEx外壳正在运行吗?

要检查conn结构内部的内容(或任何其他变量),您只需使用
IO即可。检查conn
并像往常一样使用
混合测试运行测试
-此处无需使用pry。例如:

defmodule HelloWeb.PageControllerTest do
  use HelloWeb.ConnCase
  test "GET /", %{conn: conn} do
    IO.inspect conn
    conn = get conn, "/"
    assert html_response(conn, 200) =~ "Welcome to Phoenix!"
  end
end
但是,如果您真的需要一个shell,您可以这样称呼它:

iex -S mix test 

ExUnit测试在.exs文件中,这意味着解释代码被写入其中。所以不能在其中设置断点

有关.exs和.ex文件的更多信息。看

如果你想查看任何地图,只需写下

    IO.inspect conn
对于简单的变量,您可以编写

    IO.puts variable_name