【问题标题】:How can I make Elixir mix test output more verbose?如何使 Elixir 混合测试输出更详细?
【发布时间】:2017-05-12 00:48:16
【问题描述】:

在我的 Elixir/Phoenix 应用程序中,当我运行时

mix test

我得到如下输出:

$ mix test
....

Finished in 0.09 seconds
4 tests, 0 failures

每个成功的测试都带有点。

如何输出成功的测试名称?

在带有 rspec 的 Rails 中,我曾经使用目录中的 .rspec 文件来执行此操作,如下所示:

$ cat .rspec
--color
-fd
--tty

Elixir 中是否有等价物?

【问题讨论】:

    标签: testing elixir phoenix-framework elixir-mix verbosity


    【解决方案1】:

    要打印通过测试的名称,您可以将--trace 参数传递给mix test。例如,这是mix test --tracehttpoison 包的当前主分支上的输出:

    $ mix test --trace
    
    HTTPoisonTest
    Starting HTTParrot on port 8080
    Starting HTTParrot on port 8433 (SSL)
    Starting HTTParrot on unix socket httparrot.sock
      * test post binary body (97.1ms)
      * test https scheme (57.8ms)
      * test option follow redirect relative url (4.0ms)
      * test option follow redirect absolute url (2.6ms)
      * test put (0.6ms)
      * test request headers as a map (0.5ms)
      * test get (1.5ms)
      * test head (0.5ms)
      * test delete (1.5ms)
      * test asynchronous redirected get request (2.3ms)
      * test send cookies (4.9ms)
      * test post charlist body (0.7ms)
      * test patch (0.5ms)
      * test post form data (0.6ms)
      * test exception (6.0ms)
      * test get with params (2.8ms)
      * test asynchronous request (0.5ms)
      * test explicit http scheme (0.5ms)
      * test put without body (0.8ms)
      * test multipart upload (8.5ms)
      * test options (0.5ms)
      * test basic_auth hackney option (1.6ms)
      * test http+unix scheme (4.4ms)
      * test asynchronous request with explicit streaming using [async: :once] (304.1ms)
      * test cached request (2.1ms)
      * test post streaming body (3.8ms)
      * test char list URL (0.7ms)
    
    HTTPoisonBaseTest
      * test request body using ExampleDefp (124.1ms)
      * test passing ssl option (110.9ms)
      * test passing connect_timeout option (109.9ms)
      * test passing recv_timeout option (103.4ms)
      * test passing proxy option (106.6ms)
      * test passing follow_redirect option (105.3ms)
      * test passing proxy option with proxy_auth (106.9ms)
      * test request raises error tuple (104.9ms)
      * test passing max_redirect option (115.6ms)
      * test request body using Example (111.6ms)
    
    
    Finished in 2.0 seconds
    37 tests, 0 failures
    
    Randomized with seed 264353
    

    您还可以通过更改test_helper.exs 中的ExUnit.start 行来将此选项默认设置为true:

    ExUnit.start(trace: true)
    

    如果您想要完全自定义的输出,您可以实现自己的格式化程序(参见https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit/cli_formatter.ex 示例;这是默认格式化程序)并配置 ExUnit 以使用它:

    ExUnit.start(formatters: [YourFormatterModule])
    

    【讨论】:

      【解决方案2】:

      --trace 是您正在寻找的选项:https://hexdocs.pm/mix/Mix.Tasks.Test.html

      希望有帮助!

      【讨论】:

        猜你喜欢
        • 2015-04-27
        • 2019-11-17
        • 2020-01-30
        • 2020-04-24
        • 2017-05-10
        • 1970-01-01
        • 2017-02-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多