测试嵌套文件夹中的 Phoenix Controller

标签 testing elixir phoenix-framework

我有一个 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/

相关文章:

testing - Katalon Studio 可以在运行测试时读取验证码吗

vb.net - 如何在 SMTPClient.Send [VB.NET] 之前测试 SMTP 连接

testing - by.id 比 by.tagname 好吗?

mongodb - 如何连接到elixir中的mongo副本集群

elixir - 在 Phoenix/Elixir 中测试渲染

visual-studio - 为什么 Visual Studio Tester Edition 不能运行我的 Web 测试?

Elixir + Phoenix Channels 内存消耗

visual-studio - 收到错误 : "nmake" not found in path when trying to create/migrate/run

postgresql - 无法混合 ecto.create,角色 'postgres' 不存在

testing - doctest Phoenix 语境