Class: Test::Unit::TestResult

Inherits:
Object
  • Object
show all
Includes:
NullResultContainerInitializer, TestResultErrorSupport, TestResultFailureSupport, TestResultNotificationSupport, TestResultOmissionSupport, TestResultPendingSupport, Util::Observable
Defined in:
lib/test/unit/testresult.rb,
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

Util::Observable::NOTHING

Instance Attribute Summary collapse

Attributes included from TestResultNotificationSupport

#notifications

Attributes included from TestResultOmissionSupport

#omissions

Attributes included from TestResultPendingSupport

#pendings

Attributes included from TestResultErrorSupport

#errors

Attributes included from TestResultFailureSupport

#failures

Instance Method Summary collapse

Methods included from TestResultNotificationSupport

#add_notification, #notification_count

Methods included from TestResultOmissionSupport

#add_omission, #omission_count

Methods included from TestResultPendingSupport

#add_pending, #pending_count

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

#initializeTestResult

Constructs a new, empty TestResult.



39
40
41
42
43
44
45
46
# File 'lib/test/unit/testresult.rb', line 39

def initialize
  @run_count, @pass_count, @assertion_count = 0, 0, 0
  @summary_generators = []
  @problem_checkers = []
  @faults = []
  @stop_tag = nil
  initialize_containers
end

Instance Attribute Details

#assertion_countObject (readonly)

Returns the value of attribute assertion_count



34
35
36
# File 'lib/test/unit/testresult.rb', line 34

def assertion_count
  @assertion_count
end

#faultsObject (readonly)

Returns the value of attribute faults



34
35
36
# File 'lib/test/unit/testresult.rb', line 34

def faults
  @faults
end

#pass_countObject (readonly)

Returns the value of attribute pass_count



34
35
36
# File 'lib/test/unit/testresult.rb', line 34

def pass_count
  @pass_count
end

#run_countObject (readonly)

Returns the value of attribute run_count



34
35
36
# File 'lib/test/unit/testresult.rb', line 34

def run_count
  @run_count
end

#stop_tagObject

Returns the value of attribute stop_tag



36
37
38
# File 'lib/test/unit/testresult.rb', line 36

def stop_tag
  @stop_tag
end

Instance Method Details

#add_assertionObject

Records an individual assertion.



60
61
62
63
64
# File 'lib/test/unit/testresult.rb', line 60

def add_assertion
  @assertion_count += 1
  notify_listeners(PASS_ASSERTION, self)
  notify_changed
end

#add_passObject



55
56
57
# File 'lib/test/unit/testresult.rb', line 55

def add_pass
  @pass_count += 1
end

#add_runObject

Records a test run.



49
50
51
52
53
# File 'lib/test/unit/testresult.rb', line 49

def add_run
  @run_count += 1
  notify_listeners(FINISHED, self)
  notify_changed
end

#pass_percentageObject



107
108
109
110
111
112
113
114
# File 'lib/test/unit/testresult.rb', line 107

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.

Returns:

  • (Boolean)


103
104
105
# File 'lib/test/unit/testresult.rb', line 103

def passed?
  @problem_checkers.all? {|checker| not __send__(checker)}
end

#statusObject

Returnes a string that shows result status.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/test/unit/testresult.rb', line 75

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

#stopObject



93
94
95
# File 'lib/test/unit/testresult.rb', line 93

def stop
  throw @stop_tag
end

#summaryObject

Returns a string contain the recorded runs, assertions, failures and errors in this TestResult.



68
69
70
71
72
# File 'lib/test/unit/testresult.rb', line 68

def summary
  ["#{run_count} tests",
   "#{assertion_count} assertions",
   *@summary_generators.collect {|generator| __send__(generator)}].join(", ")
end

#to_sObject



97
98
99
# File 'lib/test/unit/testresult.rb', line 97

def to_s
  summary
end