B
Brian Adkins
I just ran into a problem with Test::Unit exhibited by the two files
below and the output of 'ruby tc_child.rb':
--- tc_child.rb ---
require 'tc_parent'
class ChildTest < ParentTest
def test_one
puts 'test_one called'
assert true
end
end
--- tc_child.rb ---
--- tc_parent.rb ---
require "test/unit"
class ParentTest < Test::Unit::TestCase
def setup
puts 'setup called'
end
def teardown
puts 'teardown called'
end
end
--- tc_parent.rb ---
ruby tc_child.rb
Loaded suite tc_child
Started
setup called
test_one called
teardown called
..setup called
Fteardown called
Finished in 0.004709 seconds.
1) Failure:
default_test(ParentTest) [tc_child.rb:4]:
No tests were specified.
2 tests, 2 assertions, 1 failures, 0 errors
---
So apparently it's inadvisable to insert a class between
Test::Unit::TestCase and a 'leaf node' test class. In my case, I ended
up moving the base functionality into a module that I mixed into
tc_child.rb, and this actually worked better for what I'm trying to
accomplish. The flexibility of modules is a great feature of Ruby.
Is there a way to instruct Test::Unit to not attempt to run tests in
intermediate classes in the hierarchy?
Brian Adkins
below and the output of 'ruby tc_child.rb':
--- tc_child.rb ---
require 'tc_parent'
class ChildTest < ParentTest
def test_one
puts 'test_one called'
assert true
end
end
--- tc_child.rb ---
--- tc_parent.rb ---
require "test/unit"
class ParentTest < Test::Unit::TestCase
def setup
puts 'setup called'
end
def teardown
puts 'teardown called'
end
end
--- tc_parent.rb ---
ruby tc_child.rb
Loaded suite tc_child
Started
setup called
test_one called
teardown called
..setup called
Fteardown called
Finished in 0.004709 seconds.
1) Failure:
default_test(ParentTest) [tc_child.rb:4]:
No tests were specified.
2 tests, 2 assertions, 1 failures, 0 errors
---
So apparently it's inadvisable to insert a class between
Test::Unit::TestCase and a 'leaf node' test class. In my case, I ended
up moving the base functionality into a module that I mixed into
tc_child.rb, and this actually worked better for what I'm trying to
accomplish. The flexibility of modules is a great feature of Ruby.
Is there a way to instruct Test::Unit to not attempt to run tests in
intermediate classes in the hierarchy?
Brian Adkins