测试时撬 [英] Pry while testing

查看:140
本文介绍了测试时撬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Elixir领域还很新,但是玩得很开心!

I'm pretty new in Elixir, but have a lot fun with it!

我来自Ruby世界,因此开始进行类比。并且存在调试工具 pry 。使用 binding.pry 我可以中断任何会话。我在Elixir中发现了类似的内容– IEx.pry 。但是当我通过 ExUnit 测试某些东西时,它不起作用。

I came from Ruby world, so start looking analogy. And there is exist debugging tool pry. Using binding.pry I can interrupt any session. I found something similar in Elixir – IEx.pry. But it doesn't work when I'm testing something through ExUnit.

问题–是否可以中断测试会话并在当前环境下运行iex?

Question – is it is possible to interrupt testing session and run iex with current environment?

推荐答案

您需要在iex会话中开始测试-您可以通过运行 iex -S混合测试来进行测试。然后,可以在测试中使用 IEx.pry

You need to start your tests inside an iex session - you can do that by running iex -S mix test. Then you can use IEx.pry inside your test:

require IEx

test "the truth" do
  one = 1
  IEx.pry
  assert one + one == 2
end

会询问您是否允许窥探会话:

You'll be asked if you want to allow prying into the session:

Request to pry #PID<0.143.0> at test/test_app_test.exs:7. Allow? [Yn]

此时所有的上下文都可以使用:

And all the context at that point will be available to you:

pry(1)> one
1

这篇关于测试时撬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆