Class: Test::Unit::TestResult
- Inherits:
-
Object
- Object
- Test::Unit::TestResult
- Includes:
- NullResultContainerInitializer, TestResultErrorSupport, TestResultFailureSupport, TestResultNotificationSupport, TestResultOmissionSupport, TestResultPendingSupport, Util::Observable
- Defined in:
- lib/test/unit/testresult.rb
Overview
Collects Test::Unit::Failure and Test::Unit::Error so that they can be displayed to the user. To this end, observers can be added to it, allowing the dynamic updating of, say, a UI.
Constant Summary collapse
- FINISHED =
name + "::FINISHED"
- CHANGED =
name + "::CHANGED"
- PASS_ASSERTION =
name + "::PASS_ASSERTION"
- FAULT =
name + "::FAULT"
Constants included from Util::Observable
Instance Attribute Summary collapse
-
#assertion_count ⇒ Object
readonly
Returns the value of attribute assertion_count.
-
#faults ⇒ Object
readonly
Returns the value of attribute faults.
-
#pass_count ⇒ Object
readonly
Returns the value of attribute pass_count.
-
#run_count ⇒ Object
readonly
Returns the value of attribute run_count.
Attributes included from TestResultNotificationSupport
Attributes included from TestResultOmissionSupport
Attributes included from TestResultPendingSupport
Attributes included from TestResultErrorSupport
Attributes included from TestResultFailureSupport
Instance Method Summary collapse
-
#add_assertion ⇒ Object
Records an individual assertion.
- #add_pass ⇒ Object
-
#add_run ⇒ Object
Records a test run.
-
#initialize ⇒ TestResult
constructor
Constructs a new, empty TestResult.
- #pass_percentage ⇒ Object
-
#passed? ⇒ Boolean
Returns whether or not this TestResult represents successful completion.
-
#status ⇒ Object
Returnes a string that shows result status.
-
#summary ⇒ Object
Returns a string contain the recorded runs, assertions, failures and errors in this TestResult.
- #to_s ⇒ Object
Methods included from TestResultNotificationSupport
#add_notification, #notification_count
Methods included from TestResultOmissionSupport
#add_omission, #omission_count
Methods included from TestResultPendingSupport
Methods included from TestResultErrorSupport
#add_error, #error_count, #error_occurred?
Methods included from TestResultFailureSupport
#add_failure, #failure_count, #failure_occurred?
Methods included from Util::Observable
#add_listener, #notify_listeners, #remove_listener
Constructor Details
#initialize ⇒ TestResult
Constructs a new, empty TestResult.
42 43 44 45 46 47 48 |
# File 'lib/test/unit/testresult.rb', line 42 def initialize @run_count, @pass_count, @assertion_count = 0, 0, 0 @summary_generators = [] @problem_checkers = [] @faults = [] initialize_containers end |
Instance Attribute Details
#assertion_count ⇒ Object (readonly)
Returns the value of attribute assertion_count.
39 40 41 |
# File 'lib/test/unit/testresult.rb', line 39 def assertion_count @assertion_count end |
#faults ⇒ Object (readonly)
Returns the value of attribute faults.
39 40 41 |
# File 'lib/test/unit/testresult.rb', line 39 def faults @faults end |
#pass_count ⇒ Object (readonly)
Returns the value of attribute pass_count.
39 40 41 |
# File 'lib/test/unit/testresult.rb', line 39 def pass_count @pass_count end |
#run_count ⇒ Object (readonly)
Returns the value of attribute run_count.
39 40 41 |
# File 'lib/test/unit/testresult.rb', line 39 def run_count @run_count end |
Instance Method Details
#add_assertion ⇒ Object
Records an individual assertion.
62 63 64 65 66 |
# File 'lib/test/unit/testresult.rb', line 62 def add_assertion @assertion_count += 1 notify_listeners(PASS_ASSERTION, self) notify_changed end |
#add_pass ⇒ Object
57 58 59 |
# File 'lib/test/unit/testresult.rb', line 57 def add_pass @pass_count += 1 end |
#add_run ⇒ Object
Records a test run.
51 52 53 54 55 |
# File 'lib/test/unit/testresult.rb', line 51 def add_run @run_count += 1 notify_listeners(FINISHED, self) notify_changed end |
#pass_percentage ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/test/unit/testresult.rb', line 105 def pass_percentage n_tests = @run_count - omission_count if n_tests.zero? 0 else 100.0 * (@pass_count / n_tests.to_f) end end |
#passed? ⇒ Boolean
Returns whether or not this TestResult represents successful completion.
101 102 103 |
# File 'lib/test/unit/testresult.rb', line 101 def passed? @problem_checkers.all? {|checker| not __send__(checker)} end |
#status ⇒ Object
Returnes a string that shows result status.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/test/unit/testresult.rb', line 77 def status if passed? if pending_count > 0 "pending" elsif omission_count > 0 "omission" elsif notification_count > 0 "notification" else "pass" end elsif error_count > 0 "error" elsif failure_count > 0 "failure" end end |
#summary ⇒ Object
Returns a string contain the recorded runs, assertions, failures and errors in this TestResult.
70 71 72 73 74 |
# File 'lib/test/unit/testresult.rb', line 70 def summary ["#{run_count} tests", "#{assertion_count} assertions", *@summary_generators.collect {|generator| __send__(generator)}].join(", ") end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/test/unit/testresult.rb', line 95 def to_s summary end |