Class: MyTestSuite

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/geotree/tools.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#_suite_active?Boolean

True if called within suite-level setup/teardown window

Returns:

  • (Boolean)


580
581
582
# File 'lib/geotree/tools.rb', line 580

def _suite_active?
  !(@__name__ == "test_00_setup" || @__name__ == "test_zzzzzz_teardown")
end

#method_setupObject



612
613
# File 'lib/geotree/tools.rb', line 612

def method_setup
end

#method_teardownObject



615
616
# File 'lib/geotree/tools.rb', line 615

def method_teardown
end

#setupObject



584
585
586
587
588
589
590
591
592
593
594
# File 'lib/geotree/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_setupObject



606
607
# File 'lib/geotree/tools.rb', line 606

def suite_setup
end

#suite_teardownObject



609
610
# File 'lib/geotree/tools.rb', line 609

def suite_teardown
end

#teardownObject



596
597
598
599
600
601
602
603
604
# File 'lib/geotree/tools.rb', line 596

def teardown
  if _suite_active?
    if !defined? @@suiteSetup
      suite_teardown
    end
    return 
  end
  method_teardown
end

#test_00_setupObject

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



567
568
569
570
# File 'lib/geotree/tools.rb', line 567

def test_00_setup
  @@suiteSetup = true
  suite_setup()
end

#test_zzzzzz_teardownObject

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



574
575
576
577
# File 'lib/geotree/tools.rb', line 574

def test_zzzzzz_teardown
  suite_teardown()
  @@suiteSetup = false
end