… of many things …

… of many things … header image 2

Creating Test Suites In Ruby

January 6th, 2006 · No Comments

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:
  1. require 'test/unit'
  2. require 'test/unit/testsuite'
  3. require 'test/unit/ui/gtk2/testrunner'
  4. require 'test/unit/ui/console/testrunner'
  5.  
  6. class AllTests
  7.   TESTS = Array.new
  8. end
  9.  
  10. class Class
  11.   def inherited(arg)
  12.     if arg <Test::Unit::TestCase
  13.       AllTests::TESTS <<arg
  14.     end
  15.   end
  16. end
  17.  
  18. Dir.glob('*test.rb').each {|f|
  19.   require f
  20. }
  21.  
  22. class AllTests
  23.   def self.suite
  24.     suite = Test::Unit::TestSuite.new('All Tests')
  25.     TESTS.each {|t| suite <<t.suite}
  26.     suite
  27.   end
  28. end
  29.  
  30. if __FILE__ == $0
  31.   Test::Unit::UI::GTK2::TestRunner.run(AllTests)
  32. else
  33.   Test::Unit::UI::Console::TestRunner.run(AllTests)
  34. end

Tags: Software · Ruby

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment