Test::Unit in 1.8

So far I’ve noticed two changes in the Test::Unit included with 1.8.
They’ve probably been in Test::Unit for I long time, but I’m just
encountering them now with 1.8, due to laziness.

First, you have to define #setup instead of #set_up. I guess I prefer
the new way (I remember a long discussion some time ago), but it might
be nice to get a warning that you have defined #set_up, and it will not
be called…

Second, you can no longer define a subclass of TestCase to be used as an
"abstract" base class of other test case classes. For example, the
following flunks, because BaseTest has no tests:

require ‘test/unit’

class BaseTest < Test::Unit::TestCase
def do_foo_test
puts "testing foo"
end
end

class DerivedTest < BaseTest
def test_derived
do_foo_test
end
end

I’ve gotten around this by adding a dummy test method to my base class.
I could also have made it a mixin. It’s just a minor annoyance.

Maybe it would be possible to have a class method of TestCase that marks
the class as “abstract”? E.g.,

class BaseTest < Test::Unit::TestCase
abstract_test_class

end

Hope this helps someone who’s as slow to upgrade as me…

First, you have to define #setup instead of #set_up. I guess I prefer
the new way (I remember a long discussion some time ago), but it might
be nice to get a warning that you have defined #set_up, and it will not
be called…

Hmmm… a warning would be nice. Have to see about that.

Second, you can no longer define a subclass of TestCase to be used as an
“abstract” base class of other test case classes. For example, the
following flunks, because BaseTest has no tests:

[ruby-talk:76201] and the surrounding thread might be helpful.

Nathaniel

<:((><

···

Joel VanderWerf [mailto:vjoel@PATH.Berkeley.EDU] wrote:

Nathaniel Talbott wrote:

Second, you can no longer define a subclass of TestCase to be used as an
“abstract” base class of other test case classes. For example, the
following flunks, because BaseTest has no tests:

[ruby-talk:76201] and the surrounding thread might be helpful.

Thanks for the tip, Nathaniel. (Gee, have I been out of touch, I didn’t
even think to scan the archive…)

Your suggestion to define an empty #default_test is better than what I
had come up with.