How to output names of ruby unit tests

北城以北 提交于 2019-12-18 11:53:37

问题


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

回答1:


If you're testing in rails you can use

rake test TESTOPTS=-v



回答2:


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



回答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)


来源:https://stackoverflow.com/questions/427451/how-to-output-names-of-ruby-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!