While looking through the test code I realized I don’t see what
actually runs.
My tests extend Test::Unit::TestCase, and define tests as
def test_sometestname
some testing stuff
end
I scanned Test::Unit::TestCase and I see a bunch of function
definitions, but I don’t see what runs. I guess I’m looking for a
method or piece of code that starts running, initializes things, finds
the test_* test methods and starts running them.
It’s probably staring me in the face. Please point it out to me.
I scanned Test::Unit::TestCase and I see a bunch of function
definitions, but I don’t see what runs. I guess I’m looking for a
method or piece of code that starts running, initializes things, finds
the test_* test methods and starts running them.
To expand on Austin’s answer just a little: I think the magic that
you’re looking for is at the tail end of unit.rb, in the
lib/1.8/test/unit directory of the standard library. Test::Unit takes
advantage of the at_exit() method to register a little bit of code
that invokes the Test::Unit AutoRunner class right before the
interpreter exits.
I see the code you refer to. Now I wonder why it is done using the
at_exit method – seems a little obtuse to me.
In Python’s unit testing framework, you have to explicitly include
this code in every one of your test files. It’s a real pain. Using the
at_exit hook in Ruby makes your unit tests cleaner.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.