Tuesday, January 17, 2006

Test

This is a test of posting by sending email.

--
Jason Rogers

"I am crucified with Christ: nevertheless I live; yet not I,
but Christ liveth in me: and the life which I now live in
the flesh I live by the faith of the Son of God, who loved
me, and gave himself for me."
Galatians 2:20

Friday, January 06, 2006

Creating Test Suites In Ruby

The following is one way to create a suite of tests automatically in Ruby. There are probably better ways, but this works for me.


require 'test/unit'
require 'test/unit/testsuite'
require 'test/unit/ui/gtk2/testrunner'
require 'test/unit/ui/console/testrunner'

# The initial definition of AllTests is here so
# that we can refer to it in our redefinition of
# Class#inherited

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