The following is one way to create a suite of tests automatically in Ruby. There are probably better ways, but this works for me.
RUBY:
-
require 'test/unit'
-
require 'test/unit/testsuite'
-
require 'test/unit/ui/gtk2/testrunner'
-
require 'test/unit/ui/console/testrunner'
-
-
class AllTests
-
TESTS = Array.new
-
end
-
-
class Class
-
def inherited(arg)
-
if arg <Test::Unit::TestCase
-
AllTests::TESTS <<arg
-
end
-
end
-
end
-
-
Dir.glob('*test.rb').each {|f|
-
require f
-
}
-
-
class AllTests
-
def self.suite
-
suite = Test::Unit::TestSuite.new('All Tests')
-
TESTS.each {|t| suite <<t.suite}
-
suite
-
end
-
end
-
-
if __FILE__ == $0
-
Test::Unit::UI::GTK2::TestRunner.run(AllTests)
-
else
-
Test::Unit::UI::Console::TestRunner.run(AllTests)
-
end
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment