Class: Test::Unit::TestSuite
- Inherits:
-
Object
- Object
- Test::Unit::TestSuite
- Defined in:
- lib/test/unit/testsuite.rb
Overview
A collection of tests which can be #run.
Note: It is easy to confuse a TestSuite instance with something that has a static suite method; I know because I have trouble keeping them straight. Think of something that has a suite method as simply providing a way to get a meaningful TestSuite instance.
Constant Summary collapse
- STARTED =
name + "::STARTED"
- FINISHED =
name + "::FINISHED"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#priority ⇒ Object
Test suite that has higher priority is ran prior to test suites that have lower priority.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Instance Method Summary collapse
-
#<<(test) ⇒ Object
Adds the test to the suite.
-
#==(other) ⇒ Object
It’s handy to be able to compare TestSuite instances.
- #delete(test) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name = "Unnamed TestSuite", test_case = nil) ⇒ TestSuite
constructor
Creates a new TestSuite with the given name.
-
#run(result) {|STARTED, name| ... } ⇒ Object
Runs the tests and/or suites contained in this TestSuite.
-
#size ⇒ Object
Retuns the rolled up number of tests in this suite; i.e.
-
#to_s ⇒ Object
Overridden to return the name given the suite at creation.
Constructor Details
#initialize(name = "Unnamed TestSuite", test_case = nil) ⇒ TestSuite
Creates a new TestSuite with the given name.
31 32 33 34 35 36 37 |
# File 'lib/test/unit/testsuite.rb', line 31 def initialize(name="Unnamed TestSuite", test_case=nil) @name = name @tests = [] @test_case = test_case @n_tests = 0 @priority = 0 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/test/unit/testsuite.rb', line 21 def name @name end |
#priority ⇒ Object
Test suite that has higher priority is ran prior to test suites that have lower priority.
25 26 27 |
# File 'lib/test/unit/testsuite.rb', line 25 def priority @priority end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
21 22 23 |
# File 'lib/test/unit/testsuite.rb', line 21 def tests @tests end |
Instance Method Details
#<<(test) ⇒ Object
Adds the test to the suite.
53 54 55 56 |
# File 'lib/test/unit/testsuite.rb', line 53 def <<(test) @tests << test self end |
#==(other) ⇒ Object
It’s handy to be able to compare TestSuite instances.
82 83 84 85 86 |
# File 'lib/test/unit/testsuite.rb', line 82 def ==(other) return false unless(other.kind_of?(self.class)) return false unless(@name == other.name) @tests == other.tests end |
#delete(test) ⇒ Object
58 59 60 |
# File 'lib/test/unit/testsuite.rb', line 58 def delete(test) @tests.delete(test) end |
#empty? ⇒ Boolean
71 72 73 |
# File 'lib/test/unit/testsuite.rb', line 71 def empty? tests.empty? end |
#run(result) {|STARTED, name| ... } ⇒ Object
Runs the tests and/or suites contained in this TestSuite.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/test/unit/testsuite.rb', line 41 def run(result, &progress_block) yield(STARTED, name) run_startup(result) while test = @tests.shift @n_tests += test.size test.run(result, &progress_block) end run_shutdown(result) yield(FINISHED, name) end |
#size ⇒ Object
Retuns the rolled up number of tests in this suite; i.e. if the suite contains other suites, it counts the tests within those suites, not the suites themselves.
65 66 67 68 69 |
# File 'lib/test/unit/testsuite.rb', line 65 def size total_size = @n_tests @tests.each { |test| total_size += test.size } total_size end |
#to_s ⇒ Object
Overridden to return the name given the suite at creation.
77 78 79 |
# File 'lib/test/unit/testsuite.rb', line 77 def to_s @name end |