【问题标题】:Ruby test-unit not showing summary after testsRuby 测试单元在测试后未显示摘要
【发布时间】:2021-05-09 19:28:13
【问题描述】:

通常 Ruby 测试单元会在完成后显示运行的测试摘要,如下所示:

Finished in 0.117158443 seconds.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10 tests, 10 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
298.74 tests/s, 0.00 assertions/s

这是可行的,但现在发生了一些变化,当单元测试运行时,它会显示点,然后停止。我尝试将一些测试文件重新组织到不同的目录中,并确保更改测试运行程序中的文件路径。此外,这些点与测试/断言的数量不匹配。

Loaded suite test
Started
.................$prompt> // <<-- does not put newline here.

我注意到,如果我从另一个目录运行 testrunner,将显示摘要,但它会导致测试依赖项出错。我应该能够从同一目录运行 testrunner。这是我正在使用的测试运行程序的一个示例:https://test-unit.github.io/test-unit/en/file.how-to.html。最后没有显示的原因是什么?

【问题讨论】:

    标签: ruby unit-testing testunit


    【解决方案1】:

    似乎test-unit.yml 文件与运行脚本的目录不在同一目录中可能是个问题。

    请参阅here in the code 或在您发布的文档中的同一部分。

    在此处查看它的配置方式,例如:

    runner: console
    console_options:
      color_scheme: inverted
    color_schemes:
      inverted:
        success:
          name: red
          bold: true
        failure:
          name: green
          bold: true
    

    这个part of the code 文档真的很突出:

      # ## Test Runners
      #
      # So, now you have this great test class, but you still
      # need a way to run it and view any failures that occur
      # during the run. There are some test runner; console test
      # runner, GTK+ test runner and so on. The console test
      # runner is automatically invoked for you if you require
      # 'test/unit' and simply run the file. To use another
      # runner simply set default test runner ID to
      # Test::Unit::AutoRunner:
    

    也许您需要在 YML 文件中指定该运行器?

    如果不了解您是如何调用脚本和目录组织的,就很难判断是什么导致了该问题,但我认为它始于它没有读取该 yaml 文件。

    如果一切都失败了,让我推荐两个用于 Ruby 的优秀单元测试库,如果您觉得有必要切换到使用更广泛的库:

    1. minitest
    2. RSpec

    编辑:您还可以将目录恢复为与以前相同的顺序,并在您的 Gemfile 中为该测试单元 gem 硬编码为您工作的最后一个版本,例如 `"test-unit": "3.4 .0"。

    【讨论】:

    • 感谢您的建议!所以我根本没有使用配置文件(现在或以前),并且更早地得到了正常的输出。如果可能,不希望添加额外的配置文件(如果出于其他原因不需要)。也同意其他库之一可能更好,但我试图坚持使用 test-unit,因为它是内置的,我的大多数测试已经在使用它,除了这个问题。
    • 我建议如果 gem 本身发生变化,那么可能需要该配置文件来将输出运行器设置为不采用点格式。同时,如果不了解目录结构或它之前和之后的外观,就很难说出导致问题的原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    相关资源
    最近更新 更多