How to output names of ruby unit tests
Asked Answered
L

3

13

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
Lampblack answered 9/1, 2009 at 9:2 Comment(0)
L
9

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
Lampblack answered 9/1, 2009 at 9:12 Comment(1)
You don't need the =verbose after the --verbose, or the v after -v... just running with -v or --verbose will do the trick.Elma
H
17

If you're testing in rails you can use

rake test TESTOPTS=-v
Hiroshige answered 9/1, 2009 at 15:15 Comment(0)
L
9

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
Lampblack answered 9/1, 2009 at 9:12 Comment(1)
You don't need the =verbose after the --verbose, or the v after -v... just running with -v or --verbose will do the trick.Elma
L
4

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)
Lampblack answered 9/1, 2009 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.