Class: MyTestSuite
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- MyTestSuite
- Defined in:
- lib/lenc/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
-
The usual setup / teardown methods should NOT be overridden; instead, use the method_xxx alternatives.
-
The base class implementations of method_/suite_xxx do nothing.
-
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.
-
Avoid naming test methods that fall outside of test_01 ... test_zz.
Instance Method Summary collapse
-
#_suite_active? ⇒ Boolean
True if called within suite-level setup/teardown window.
- #method_setup ⇒ Object
- #method_teardown ⇒ Object
- #setup ⇒ Object
- #suite_setup ⇒ Object
- #suite_teardown ⇒ Object
- #teardown ⇒ Object
-
#test_00_setup ⇒ Object
This is named to be the FIRST test called.
-
#test_zzzzzz_teardown ⇒ Object
This is named to be the LAST test called.
Instance Method Details
#_suite_active? ⇒ Boolean
True if called within suite-level setup/teardown window
580 581 582 |
# File 'lib/lenc/tools.rb', line 580 def _suite_active? !(@__name__ == "test_00_setup" || @__name__ == "test_zzzzzz_teardown") end |
#method_setup ⇒ Object
612 613 |
# File 'lib/lenc/tools.rb', line 612 def method_setup end |
#method_teardown ⇒ Object
615 616 |
# File 'lib/lenc/tools.rb', line 615 def method_teardown end |
#setup ⇒ Object
584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/lenc/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 ⇒ Object
606 607 |
# File 'lib/lenc/tools.rb', line 606 def suite_setup end |
#suite_teardown ⇒ Object
609 610 |
# File 'lib/lenc/tools.rb', line 609 def suite_teardown end |
#teardown ⇒ Object
596 597 598 599 600 601 602 603 604 |
# File 'lib/lenc/tools.rb', line 596 def teardown if _suite_active? if !defined? @@suiteSetup suite_teardown end return end method_teardown end |
#test_00_setup ⇒ Object
This is named to be the FIRST test called. It will do suite-level setup, and nothing else.
567 568 569 570 |
# File 'lib/lenc/tools.rb', line 567 def test_00_setup @@suiteSetup = true suite_setup() end |
#test_zzzzzz_teardown ⇒ Object
This is named to be the LAST test called. It will do suite-level teardown, and nothing else.
574 575 576 577 |
# File 'lib/lenc/tools.rb', line 574 def test_zzzzzz_teardown suite_teardown() @@suiteSetup = false end |