【问题标题】:How to get the status of tests in my file using hound?如何使用 hound 获取我的文件中的测试状态?
【发布时间】:2019-09-27 20:55:55
【问题描述】:

ExUnit 提供了一些获取测试结果的方法。我不知道如何使用它https://hexdocs.pm/ex_unit/ExUnit.Test.htmlhttps://hexdocs.pm/ex_unit/ExUnit.Formatter.html

我在一个文件中有多个测试。如何在最后生成结果,例如测试名称和状态?

我正在使用 hound 编写测试。 提前致谢。

【问题讨论】:

    标签: elixir ex-unit hound


    【解决方案1】:

    首先,可以为此目的使用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()
    

    【讨论】:

      猜你喜欢
      • 2018-08-10
      • 1970-01-01
      • 2017-09-19
      • 2015-06-07
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多