From: ara.t.howard@... Date: 2007-03-20T14:22:53+09:00 Subject: Re: Test::Unit::TestCase derived classes don't work when test methods are generated dynamically On Tue, 20 Mar 2007, Derek Wong wrote: here's an example of dynamic tests http://codeforpeople.com/lib/ruby/xx/xx-2.0.0/test/xx.rb the point is that you need the tests defined before intialize is called so you need to dynamically add them as class scope. harp:~ > cat a.rb require 'test/unit' require 'test/unit/assertions' class TestGenerator < Test::Unit::TestCase def setup puts "Setting up" end def teardown puts "Tearing down" end def self.createtests(testname) puts "Method name: #{testname}" define_method(testname) { puts "#{testname}" assert_equal("a", "a", "") } end def test_d puts "test_d" assert_equal("d", "d", "") test_a() test_b() test_c() end createtests("test_a") puts "Created test_a" createtests("test_b") puts "Created test_b" createtests("test_c") puts "Created test_c" def initialize(test_method_name) my_methods_list = self.methods.sort my_methods_list.each do |method| #puts "Methods supported #{method}" end super(test_method_name) end end harp:~ > ruby a.rb Method name: test_a Created test_a Method name: test_b Created test_b Method name: test_c Created test_c Loaded suite a Started Setting up test_a Tearing down .Setting up test_b Tearing down .Setting up test_c Tearing down .Setting up test_d test_a test_b test_c Tearing down . Finished in 0.001139 seconds. 4 tests, 7 assertions, 0 failures, 0 errors regards. -a -- be kind whenever possible... it is always possible. - the dalai lama