can't get test unit startup to work in ruby 1.9.2
Asked Answered
C

2

6

I am using Ruby 1.9.2 (ruby -v yields :ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]), and I am trying to get this to work:

require 'test/unit'

class TestStartup < Test::Unit::TestCase
  def self.startup
    puts "startup"
  end
  def test1
    puts "in test1"
  end
end 

when I run it, I get

Loaded suite test_startup
Started
in test1
.
Finished in 0.000395 seconds. 


1 tests, 0 assertions, 0 failures, 0 errors, 0 skips

I had a hard time finding documentation on this feature, other than scattered posts here on SO and the like.

And yes, I want to use this feature and not setup.

TIA

Coen answered 3/10, 2011 at 19:17 Comment(1)
test-unit.rubyforge.org/test-unit/Test/Unit/TestCase.html mentions that it is def self.startup, not def startup, so that wasn't the problem.Clathrate
M
2

Ruby 1.9.x bundles minitest not Test::Unit. Test::Unit bundled in Ruby 1.8.x had not been improved but unbundled Test::Unit (test-unit 2) will be improved actively.

So you must be using the Test::Unit gem? Is it perhaps an older version which doesn't support this feature?

Moshe answered 3/10, 2011 at 19:32 Comment(4)
I had test-unit installed, but since it my code wasn't doing what I wanted it to do, I tried uninstalling to see if that would help, but it made no difference. So if it works in test-unit, how to I actually use test-unit and not test/unit? When I use "require 'test-unit' (after installing the gem, test-unit), I get an error.Coen
Nevermind, found the page that shows how to do it: gem "test-unit" (then) require 'test/unit'Coen
@user119282: If your answer has been solved, don't forget to mark this answer as accepted when you're able to do so.Clathrate
I had a similar problem. I had to apply user119282's solution of calling gem "test-unit" everywhere in my code that I required 'test/unit'. Otherwise, if the first place the require code hit lacked the call to gem "test-unit", then it would still use the old code and not work.Aubine
B
2

Ruby 1.9.2 uses Minitest instead of Test::Unit by default, so it might be that this feature is missing from Minitest.

Barnardo answered 3/10, 2011 at 19:38 Comment(2)
What you said looks to be true.Coen
I'm glad I found this answer, otherwise I would have had to bug the person sitting next to me. Thanks!Alphonse

© 2022 - 2024 — McMap. All rights reserved.