ExUnit 提供了一些获取测试结果的方法。我不确定如何使用它https://hexdocs.pm/ex_unit/ExUnit.Test.html和https://hexdocs.pm/ex_unit/ExUnit.Formatter.html。
我在一个文件中有多个测试。如何在最后生成结果,例如 Test name 和 Status ?
我正在使用猎犬编写测试。提前致谢。
ExUnit 提供了一些获取测试结果的方法。我不确定如何使用它https://hexdocs.pm/ex_unit/ExUnit.Test.html和https://hexdocs.pm/ex_unit/ExUnit.Formatter.html。
我在一个文件中有多个测试。如何在最后生成结果,例如 Test name 和 Status ?
我正在使用猎犬编写测试。提前致谢。
首先,可以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()