首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >测试时禁止记录器

测试时禁止记录器
EN

Stack Overflow用户
提问于 2017-12-28 01:06:19
回答 3查看 5.4K关注 0票数 17

我想知道在测试时如何禁用Elixir中的日志记录。在我当前的代码中,我测试记录器消息,所以我不想完全禁用它,而是在任何测试停止通过之前隐藏消息。

我正在使用mix和ExUnit来管理和测试我的项目。

代码语言:javascript
运行
复制
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
EN

Stack Overflow用户

发布于 2018-09-06 18:23:06

要么使用ExUnit.CaptureLog

代码语言:javascript
运行
复制
import ExUnit.CaptureLog

test "example" do
   assert capture_log(fn ->
      Logger.error "log msg"
   end) =~ "log msg"
end

或者,如果您只想忽略任何日志,那么:

代码语言:javascript
运行
复制
@tag capture_log: true
test "example" do
    Logger.error "log msg"
end
票数 26
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47996005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档