class MyTestSuite

A simple extension to Ruby's Test::Unit class that provides suite-level setup/teardown methods.

If test suite functionality is desired within a script, then require 'test/unit' before requiring 'tools.rb'. This will cause the following class, MyTestSuite, to be defined.

The user's test script can define subclasses of this, and declare test methods with the name 'test_xxxx', where xxxx is lexicographically between 01 and zz.

There are two levels of setup/teardown called : suite level, and method level. For example, if the user's test class performs two tests:

def test_b   ... end
def test_c   ... end

Then the test framework will make these calls:

suite_setup

method_setup
test_b
method_teardown

method_setup
test_c
method_teardown

suite_teardown

Notes


1) The usual setup / teardown methods should NOT be overridden; instead, use the method_xxx alternatives.

2) The base class implementations of method_/suite_xxx do nothing.

3) The number of test cases reported may be higher than you expect, since there are additional test methods defined by the TestSuite class to implement the suite setup / teardown functionality.

4) Avoid naming test methods that fall outside of test_01 … test_zz.

Public Instance Methods

_suite_active?() click to toggle source

True if called within suite-level setup/teardown window

# File lib/tokn/tools.rb, line 580
def _suite_active?
  !(@__name__ == "test_00_setup" || @__name__ == "test_zzzzzz_teardown")
end
method_setup() click to toggle source
# File lib/tokn/tools.rb, line 612
def method_setup
end
method_teardown() click to toggle source
# File lib/tokn/tools.rb, line 615
def method_teardown
end
setup() click to toggle source
# File lib/tokn/tools.rb, line 584
def setup
  if _suite_active?
    # If only a specific test was requested, the
    # suite setup may not have run... if not, do it now.
    if !defined? @@suiteSetup
      suite_setup
    end
    return 
  end
  method_setup
end
suite_setup() click to toggle source
# File lib/tokn/tools.rb, line 606
def suite_setup
end
suite_teardown() click to toggle source
# File lib/tokn/tools.rb, line 609
def suite_teardown
end
teardown() click to toggle source
# File lib/tokn/tools.rb, line 596
def teardown
  if _suite_active?
    if !defined? @@suiteSetup
      suite_teardown
    end
    return 
  end
  method_teardown
end
test_00_setup() click to toggle source

This is named to be the FIRST test called. It will do suite-level setup, and nothing else.

# File lib/tokn/tools.rb, line 567
def test_00_setup
  @@suiteSetup = true
  suite_setup()
end
test_zzzzzz_teardown() click to toggle source

This is named to be the LAST test called. It will do suite-level teardown, and nothing else.

# File lib/tokn/tools.rb, line 574
def test_zzzzzz_teardown
  suite_teardown()
  @@suiteSetup = false
end