IEx.configure 相当于混合测试?
IEx.configure equivalent for mix test?
调试测试时,很容易在其中放置一些 IO.inspect
语句以查看发生了什么。这很好用,直到对象变得太大。
当 运行 mix test
时 iex
的 IEx.configure [inspect: [limit: 1000]]
的 mix
是多少?
IEx.configure [inspect: [limit: 1000]]
仅更改 iex
为每个输入的表达式自动调用 inspect
的选项,不会更改实际 IO.inspect
函数的行为.您必须围绕 IO.inspect
创建一个包装器并使用它代替 IO.inspect
:
test "the truth" do
list = Enum.to_list(1..100)
IO.inspect list
i list
end
defp i(item, opts \ []) do
IO.inspect(item, Keyword.put(opts, :limit, 1000))
end
输出:
$ mix test
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, ...]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
.
Finished in 0.03 seconds
1 test, 0 failures
调试测试时,很容易在其中放置一些 IO.inspect
语句以查看发生了什么。这很好用,直到对象变得太大。
当 运行 mix test
时 iex
的 IEx.configure [inspect: [limit: 1000]]
的 mix
是多少?
IEx.configure [inspect: [limit: 1000]]
仅更改 iex
为每个输入的表达式自动调用 inspect
的选项,不会更改实际 IO.inspect
函数的行为.您必须围绕 IO.inspect
创建一个包装器并使用它代替 IO.inspect
:
test "the truth" do
list = Enum.to_list(1..100)
IO.inspect list
i list
end
defp i(item, opts \ []) do
IO.inspect(item, Keyword.put(opts, :limit, 1000))
end
输出:
$ mix test
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, ...]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
.
Finished in 0.03 seconds
1 test, 0 failures