运行 "mix test" 时不打印日志
Log doesn't print when running "mix test"
我正在尝试调试,而测试未 运行ning,我有我的测试,我正在尝试打印一些东西,以便在 mix test
时可以看到元组的值是 运行。我试过这样做:
require Logger
test "creates element", %{conn: conn} do
Logger.debug "debugging #{inspect conn}"
conn = post conn, v1_content_path(conn, :create), content: @valid_attrs
...
...
end
但是没有打印任何东西!这让我发疯!
这是我阅读并做我正在做的事情的地方
编辑 也试过:
IO.puts "debugging #{inspect conn}"
编辑这里是我的test_helper.exs
的内容
ExUnit.start
Mix.Task.run "ecto.create", ~w(-r TestApp.Repo --quiet)
Mix.Task.run "ecto.migrate", ~w(-r TestApp.Repo --quiet)
Ecto.Adapters.SQL.begin_test_transaction(TestApp.Repo)
编辑 这里是我的整个测试文件:
defmodule TestApp.ContentControllerTest do
require Logger
use TestApp.ConnCase
@valid_attrs %{title: "Content Title", url: "http://www.content.com"}
@invalid_attrs %{}
setup %{conn: conn} do
conn
|> put_req_header("accept", "application/json")
{:ok, conn: conn}
end
test "my first test", %{conn: conn} do
Logger.debug "debugging #{inspect conn}"
end
end
编辑 这是mix test
的详细信息:
$ mix test
.
Finished in 2.5 seconds (0.6s on load, 1.9s on tests)
1 tests, 0 failures
Randomized with seed 685273
compile_time_purge_level
正如在对您的问题的一些评论中所指出的,通过更改 [=15= 中的 :logger
配置,可以将测试环境的 compile_time_purge_level
降低到 :debug
级别].
test.exs
config :logger,
backends: [:console],
compile_time_purge_level: :debug
运行 再次测试
mix test
我正在尝试调试,而测试未 运行ning,我有我的测试,我正在尝试打印一些东西,以便在 mix test
时可以看到元组的值是 运行。我试过这样做:
require Logger
test "creates element", %{conn: conn} do
Logger.debug "debugging #{inspect conn}"
conn = post conn, v1_content_path(conn, :create), content: @valid_attrs
...
...
end
但是没有打印任何东西!这让我发疯!
这是我阅读并做我正在做的事情的地方
编辑 也试过:
IO.puts "debugging #{inspect conn}"
编辑这里是我的test_helper.exs
的内容ExUnit.start
Mix.Task.run "ecto.create", ~w(-r TestApp.Repo --quiet)
Mix.Task.run "ecto.migrate", ~w(-r TestApp.Repo --quiet)
Ecto.Adapters.SQL.begin_test_transaction(TestApp.Repo)
编辑 这里是我的整个测试文件:
defmodule TestApp.ContentControllerTest do
require Logger
use TestApp.ConnCase
@valid_attrs %{title: "Content Title", url: "http://www.content.com"}
@invalid_attrs %{}
setup %{conn: conn} do
conn
|> put_req_header("accept", "application/json")
{:ok, conn: conn}
end
test "my first test", %{conn: conn} do
Logger.debug "debugging #{inspect conn}"
end
end
编辑 这是mix test
的详细信息:
$ mix test
.
Finished in 2.5 seconds (0.6s on load, 1.9s on tests)
1 tests, 0 failures
Randomized with seed 685273
compile_time_purge_level
正如在对您的问题的一些评论中所指出的,通过更改 [=15= 中的 :logger
配置,可以将测试环境的 compile_time_purge_level
降低到 :debug
级别].
test.exs
config :logger,
backends: [:console],
compile_time_purge_level: :debug
运行 再次测试
mix test