[英]Log doesn't print when running “mix test”
I'm trying to debug while a test is not running, I have my test and I'm trying to print something so I can see the values of a tuple when mix test
is run. 我正在尝试调试,而测试没有运行,我有我的测试,我正在尝试打印一些东西,所以我可以看到
mix test
运行时元组的值。 I've tried doing this: 我试过这样做:
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
But nothing is printed! 但没有印刷! It's driving me nuts!
这让我疯了! Here is where I read to do what I'm doing How to pretty print conn content?
这是我读到的地方,我正在做的事情如何打印conn内容?
Edit Also tried with: 编辑也试过:
IO.puts "debugging #{inspect conn}"
Edit Here the contents of my test_helper.exs 编辑我的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)
Edit Here my whole testing file: 编辑我的整个测试文件:
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
Edit Here is the detail of mix test
: 编辑这里是
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
As pointed out in some comments to your question, the compile_time_purge_level
can be reduced to the :debug
level for the test environment by changing the :logger
config in config/test.exs
. 正如您对问题的一些评论中所指出的,通过更改
config/test.exs
的:logger
config,可以将compile_time_purge_level
简化为测试环境的:debug
级别。
config :logger,
backends: [:console],
compile_time_purge_level: :debug
mix test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.