首页 > 解决方案 > Ruby 测试单元在测试后未显示摘要

问题描述

通常 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。这是我正在使用的 testrunner 的一个示例:https ://test-unit.github.io/test-unit/en/file.how-to.html 。最后没有显示的原因是什么?

标签: rubyunit-testingtestunit

解决方案


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

请参阅代码中的此处或您发布的该文档的同一部分。

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

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

部分代码文档真的很突出:

  # ## 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. 小测试
  2. 规范

编辑:您还可以将您的目录恢复为与以前相同的顺序,并在您Gemfile的测试单元 gem 中硬编码为您工作的最后一个版本,例如“测试单元”:“3.4.0”。


推荐阅读