TestUnit Inheritance Hierarchies
One of the current design features of Ruby’s TestUnit class is that every subclass of TestUnit must have at least one test method implemented. If that isn’t the case, you get a runtime error.
Sometimes, however, you’d like to use inheritance to set up a hierarchy of test “helpers”. For instance, you’d like to have some scaffolding to aid in integration testing, and you just want to inherit from IntegrationTest to make that scaffolding available.
In those cases, your superclass (IntegrationTest, in this case) simply needs to redefine the
run method as follows:
1 2 3 4 5 6
class IntegrationTest < Test::Unit::TestCase def run(*args) return if @method_name == :default_test super end end
The redefinition of
run as given above simply makes it so that the test/unit runners do not try to do anything with empty TestCase subclasses that extend IntegrationTest. I could now, for instance, have subclasses of IntegrationTest, without having to define bogus test methods in IntegrationTest.