Reputation: 21
ExUnit provides some methods to get test result. I am not sure how to use it https://hexdocs.pm/ex_unit/ExUnit.Test.html and https://hexdocs.pm/ex_unit/ExUnit.Formatter.html.
I have multiple tests in a file. How can I generate results at the end like Test name and Status ?
I am writing test using hound. Thanks in advance.
Upvotes: 1
Views: 93
Reputation: 121010
In the first place, one can use ExUnit.after_suite/1
for this purpose. The finest tuning might be done with introducing your own formatter and passing it to ExUnit.configure/1
before a call to ExUnit.start()
. Somewhat like the below (adjust to your needs.)
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()
Upvotes: 1