Test case names on run time

How can I know using test-unit the tetcases names on runtime I’m gonna
run before I
run them?

#To clarify a little what i need… let’s guess i have this test:

require ‘test/unit’
Test::Unit.run = true #I don’t want to run the tests so i set it up to

class MyTest < Test::Unit::TestCase
def test_1()
assert_equal( 2, 1+1)
def test_2()
assert_equal( 2, 4/2)
def test_3()
assert_equal( 1, 3/2)
def test_4()
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 :frowning:

What about MyTest#instance_methods?

So for example now I can get the test methods like this:

mets=MyTest.instance_methods.select{|met| met[/^test/]}

but how can I grab the Test Classes names in runtime so i can do
something like this later

my_classes.each {|my_class|
mets=eval("#{my_class}.instance_methods.select{|met| met[/^test/]}")
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 [1], it’s very readable with
comments for every method.