Ruby 测试单元在测试后不显示摘要

时间:2021-05-09 19:28:13

标签: ruby unit-testing testunit

通常 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

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

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

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

1 个答案:

答案 0 :(得分:0)

似乎是因为 <a href="#"> <object data="../../assets/images/logo.svg" type="image/svg+xml" class="logo"> </object> </a> 文件不在您运行脚本的同一目录中。

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

在这里查看它是如何配置的,例如:

test-unit.yml

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

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

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

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

如果所有其他方法都失败了,如果您觉得必须切换到更广泛使用的库,让我为您推荐两个很棒的 Ruby 单元测试库:

  1. minitest
  2. RSpec

编辑:您还可以将您的目录恢复为与以前相同的顺序,并在您的 # ## 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: 中为该测试单元 gem 进行硬编码,这是对您有用的最后一个版本,例如“测试单元”: “3.4.0”。

相关问题