我有一个 elixir umbrella 应用程序,其中包含一个 phoenix 应用程序和一个 elixir 应用程序。该应用程序按预期工作,但我在测试其中一个 Controller 时遇到问题。
当我运行测试时,文件中的测试不会运行。看起来它们在测试过程中以某种方式被跳过了。
Controller 文件看起来像...
defmodule AppName.File.Path.NameOfController do
def index(conn, params) do
render(conn, "index.html")
end
end
测试文件也相当简单,看起来像...
defmodule AppName.File.Path.NameOfControllerTest do
test "GET /"the_url/I/want", %{conn: conn} do
conn = get conn, some_path(conn, :index)
assert html_response(conn, 200) =~ "Some html"
end
end
我的项目中的所有测试都在这个文件上运行,但没有异常(exception)。我认为这可能与文件路径有关,但我看不出这会影响测试的任何原因。我还可以在运行应用程序时转到端点。
如有任何帮助,我们将不胜感激。提前致谢。
最佳答案
conn = get conn, some_path(conn, :index)
应该是 conn = get conn, name_of_path(conn, :index)
为了获得正确的路径助手,Phoenix 删除了尾随的 Controller
并将名称转换为蛇形并附加 _path
。
所以 NameOf
变成了 name_of
关于测试嵌套文件夹中的 Phoenix Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48831241/