如何输出 ruby​​ 单元测试的名称

发布于 2024-07-10 17:34:07 字数 622 浏览 13 评论 0原文

我有一个单元测试(示例已修改 Test::Unit 文档

require 'test/unit'

class TC_MyTest < Test::Unit::TestCase
  def test_something
    assert(true)
  end
end

当我执行它时,我得到:

Loaded suite C:/test
Started
.
Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

我想得到这样的东西(test_something 被输出):

Loaded suite C:/test
Started
test_something
.
Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

I have a unit test (example is modified Test::Unit documentation)

require 'test/unit'

class TC_MyTest < Test::Unit::TestCase
  def test_something
    assert(true)
  end
end

When I execute it, I get:

Loaded suite C:/test
Started
.
Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

I would like to get something like this (test_something is outputted):

Loaded suite C:/test
Started
test_something
.
Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蹲墙角沉默 2024-07-17 17:34:07

如果你在 Rails 中测试,你可以使用

rake test TESTOPTS=-v

If you're testing in rails you can use

rake test TESTOPTS=-v
苄①跕圉湢 2024-07-17 17:34:07

使用 verbose 选项运行单元测试。

test.rb -v v

test.rb --verbose=verbose

输出:

Loaded suite C:/test
Started
test_something(TC_MyTest): .

Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

Run unit test with verbose option.

test.rb -v v

or

test.rb --verbose=verbose

Output:

Loaded suite C:/test
Started
test_something(TC_MyTest): .

Finished in 0.0 seconds.

1 tests, 1 assertions, 0 failures, 0 errors
牛↙奶布丁 2024-07-17 17:34:07

如果您正在创建自己的测试运行程序,则命令行选项不起作用:

Test::Unit::UI::Console::TestRunner.run(TC_MyTest)

您必须在测试运行程序中指定详细程度。 Test::Unit::UI 选项 是:

SILENT = 0,PROGRESS_ONLY = 1,NORMAL = 2,VERBOSE = 3。

因此,对于详细:

Test::Unit::UI::Console::TestRunner.run(TC_MyTest, 3)

Command line options do not work if you are creating your own test runner:

Test::Unit::UI::Console::TestRunner.run(TC_MyTest)

You will have to specify verbosity in test runner. Test::Unit::UI options are:

SILENT = 0, PROGRESS_ONLY = 1, NORMAL = 2, VERBOSE = 3.

So, for verbose:

Test::Unit::UI::Console::TestRunner.run(TC_MyTest, 3)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文