我想知道在测试时如何禁用Elixir中的日志记录。在我当前的代码中,我测试记录器消息,所以我不想完全禁用它,而是在任何测试停止通过之前隐藏消息。
我正在使用mix和ExUnit来管理和测试我的项目。
mix test
Compiling 2 files (.ex)
.........
17:59:18.446 [warn] Code seems to be empty
.
17:59:18.447 [warn] Code doesn't contain HLT opcode
.
17:59:18.448 [warn] Code doesn't contain HLT opcode
17:59:18.448 [error] Label error doesn't exist
.....
Finished in 0.07 seconds
16 tests, 0 failures发布于 2018-09-06 18:23:06
要么使用ExUnit.CaptureLog
import ExUnit.CaptureLog
test "example" do
assert capture_log(fn ->
Logger.error "log msg"
end) =~ "log msg"
end或者,如果您只想忽略任何日志,那么:
@tag capture_log: true
test "example" do
Logger.error "log msg"
endhttps://stackoverflow.com/questions/47996005
复制相似问题