123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::TestResult

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/test/unit/testresult.rb

Overview

Collects Failure and 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

Util::Observable - Included

NOTHING

Class Method Summary

Instance Attribute Summary

TestResultNotificationSupport - Included

TestResultOmissionSupport - Included

TestResultPendingSupport - Included

TestResultErrorSupport - Included

TestResultFailureSupport - Included

Instance Method Summary

TestResultNotificationSupport - Included

#add_notification

Records a Notification.

#notification_count

Returns the number of notifications this TestResult has recorded.

#initialize_containers, #notification_summary

TestResultOmissionSupport - Included

#add_omission

Records a Omission.

#omission_count

Returns the number of omissions this TestResult has recorded.

#initialize_containers, #omission_summary

TestResultPendingSupport - Included

#add_pending

Records a Pending.

#pending_count

Returns the number of pendings this TestResult has recorded.

#initialize_containers, #pending_summary

TestResultErrorSupport - Included

#add_error

Records a Error.

#error_count

Returns the number of errors this TestResult has recorded.

#error_summary, #initialize_containers

TestResultFailureSupport - Included

#add_failure

Records a Failure.

#failure_count

Returns the number of failures this TestResult has recorded.

#failure_summary, #initialize_containers

NullResultContainerInitializer - Included

Util::Observable - Included

#add_listener

Adds the passed proc as a listener on the channel indicated by channel_name.

#notify_listeners

Calls all the procs registered on the channel indicated by channel_name.

#remove_listener

Removes the listener indicated by listener_key from the channel indicated by channel_name.

#channels

Constructor Details

.newTestResult

Constructs a new, empty TestResult.

[ GitHub ]

  
# 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 (readonly)

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 39

attr_reader :run_count, :pass_count, :assertion_count, :faults

#faults (readonly)

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 39

attr_reader :run_count, :pass_count, :assertion_count, :faults

#pass_count (readonly)

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 39

attr_reader :run_count, :pass_count, :assertion_count, :faults

#passed?Boolean (readonly)

Returns whether or not this TestResult represents successful completion.

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 101

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

#run_count (readonly)

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 39

attr_reader :run_count, :pass_count, :assertion_count, :faults

Instance Method Details

#add_assertion

Records an individual assertion.

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 62

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

#add_pass

[ GitHub ]

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

def add_pass
  @pass_count += 1
end

#add_run

Records a test run.

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 51

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

#notify_changed (private)

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 115

def notify_changed
  notify_listeners(CHANGED, self)
end

#notify_fault(fault) (private)

[ GitHub ]

  
# File 'lib/test/unit/testresult.rb', line 119

def notify_fault(fault)
  @faults << fault
  notify_listeners(FAULT, fault)
end

#pass_percentage

[ GitHub ]

  
# 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

#status

Returnes a string that shows result status.

[ GitHub ]

  
# 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

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

[ GitHub ]

  
# 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

[ GitHub ]

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

def to_s
  summary
end