【发布时间】:2019-09-27 20:55:55
【问题描述】:
ExUnit 提供了一些获取测试结果的方法。我不知道如何使用它https://hexdocs.pm/ex_unit/ExUnit.Test.html 和https://hexdocs.pm/ex_unit/ExUnit.Formatter.html。
我在一个文件中有多个测试。如何在最后生成结果,例如测试名称和状态?
我正在使用 hound 编写测试。 提前致谢。
【问题讨论】:
ExUnit 提供了一些获取测试结果的方法。我不知道如何使用它https://hexdocs.pm/ex_unit/ExUnit.Test.html 和https://hexdocs.pm/ex_unit/ExUnit.Formatter.html。
我在一个文件中有多个测试。如何在最后生成结果,例如测试名称和状态?
我正在使用 hound 编写测试。 提前致谢。
【问题讨论】:
首先,可以为此目的使用ExUnit.after_suite/1。最好的调整可能是引入您自己的格式化程序并将其传递给ExUnit.configure/1,然后再调用ExUnit.start()。有点像下面(根据您的需要调整。)
defmodule MyApp.CLIFormatter do
@moduledoc false
use GenServer
def init(opts), do: {:ok, opts}
def handle_cast({:suite_started, _opts}, config) do
IO.puts("Started")
{:noreply, config}
end
def handle_cast({:suite_finished, run_us, load_us}, config) do
IO.inspect(
{{:suite_finished, run_us, load_us}, config},
label: "Finished")
{:noreply, config}
end
def handle_cast(_, config), do: {:noreply, config}
end
ExUnit.configure(formatters: [ExUnit.CLIFormatter, MyApp.CLIFormatter])
ExUnit.start()
【讨论】: