How can I know using test-unit the tetcases names on runtime I’m gonna
run before I
#To clarify a little what i need… let’s guess i have this test:
Test::Unit.run = true #I don’t want to run the tests so i set it up to
class MyTest < Test::Unit::TestCase
assert_equal( 2, 1+1)
assert_equal( 2, 4/2)
assert_equal( 1, 3/2)
assert_equal( 1.5, 3/2.0)
I want to know here which tests would run in case this test run
so an array of test_names: test_1, test_2, test_3 and test_4
Suggestion: Create the array beforehand, then produce output by means of
either the #each, #collect or the #partition-method.
You can also play with the #eval methods to create your array on the
But I want to get the method names automatically without the need to
supply them written
I don’t know in advance the name of the class neither
What about MyTest#instance_methods?
So for example now I can get the test methods like this:
but how can I grab the Test Classes names in runtime so i can do
something like this later
puts my_class.to_s() + “:” + mets.join(", ")
What is your use case? To be honest, it does not seem very meaningful to
me to look for method names of test cases. Anyway, if are willing to
play with test-unit, you should be able to understand what is happening
in the backround. Have a look at the code, it’s the fastest way to find
out, whether your expectations can be fulfilled.
This is the source for Test::Unit::TestCase , it’s very readable with
comments for every method.