Class: Test::Unit::TestResult (Ruby 2.7.5)
Description: Class : Test::Unit::TestResult - Ruby 2.7.5

### Home Classes Methods

### In Files

- test-unit-3.3.4/lib/test/unit/testresult.rb
- test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb
- test-unit-3.3.4/lib/test/unit/ui/testrunnermediator.rb
- test-unit-3.3.4/lib/test/unit/ui/xml/testrunner.rb

### Parent

Object

### Methods

- ::new
- #add_assertion
- #add_pass
- #add_run
- #pass_percentage
- #passed?
- #status
- #stop
- #summary
- #to_s

### Included Modules

- Test::Unit::Util::Observable
- Test::Unit::NullResultContainerInitializer
- Test::Unit::TestResultFailureSupport
- Test::Unit::TestResultErrorSupport
- Test::Unit::TestResultPendingSupport
- Test::Unit::TestResultOmissionSupport
- Test::Unit::TestResultNotificationSupport

### Class/Module Index

Quicksearch

- Object
- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- Test::Unit::Assertions
- Test::Unit::Assertions::AssertExceptionHelper
- Test::Unit::Assertions::AssertExceptionHelper::WrappedException
- Test::Unit::Assertions::AssertionMessage
- Test::Unit::Assertions::AssertionMessage::ArrayInspector
- Test::Unit::Assertions::AssertionMessage::DelayedLiteral
- Test::Unit::Assertions::AssertionMessage::HashInspector
- Test::Unit::Assertions::AssertionMessage::Inspector
- Test::Unit::Assertions::AssertionMessage::Literal
- Test::Unit::Assertions::AssertionMessage::MaybeContainer
- Test::Unit::Assertions::AssertionMessage::NumericInspector
- Test::Unit::Assertions::AssertionMessage::Template
- Test::Unit::Assertions::ThrowTagExtractor
- Test::Unit::Attribute
- Test::Unit::Attribute::BaseClassMethods
- Test::Unit::Attribute::ClassMethods
- Test::Unit::Attribute::StringifyKeyHash
- Test::Unit::AttributeMatcher
- Test::Unit::AutoRunner
- Test::Unit::AutoRunner::StopOnFailureListener
- Test::Unit::AutoRunnerLoader
- Test::Unit::CodeSnippetFetcher
- Test::Unit::Collector
- Test::Unit::Collector::Descendant
- Test::Unit::Collector::Dir
- Test::Unit::Collector::Load
- Test::Unit::Collector::ObjectSpace
- Test::Unit::Collector::XML
- Test::Unit::Collector::XML::Listener
- Test::Unit::Color
- Test::Unit::Color::Error
- Test::Unit::Color::ParseError
- Test::Unit::ColorScheme
- Test::Unit::Data
- Test::Unit::Data::ClassMethods
- Test::Unit::Data::ClassMethods::Loader
- Test::Unit::DataSets
- Test::Unit::Diff
- Test::Unit::Diff::Differ
- Test::Unit::Diff::ReadableDiffer
- Test::Unit::Diff::SequenceMatcher
- Test::Unit::Diff::UTF8Line
- Test::Unit::Diff::UnifiedDiffer
- Test::Unit::Error
- Test::Unit::ErrorHandler
- Test::Unit::ExceptionHandler
- Test::Unit::ExceptionHandler::ClassMethods
- Test::Unit::Failure
- Test::Unit::FailureHandler
- Test::Unit::FaultLocationDetector
- Test::Unit::Fixture
- Test::Unit::Fixture::ClassMethods
- Test::Unit::Fixture::Fixture
- Test::Unit::Fixture::HookPoint
- Test::Unit::MixColor
- Test::Unit::Notification
- Test::Unit::NotificationHandler
- Test::Unit::NotifiedError
- Test::Unit::NullResultContainerInitializer
- Test::Unit::Omission
- Test::Unit::OmissionHandler
- Test::Unit::OmittedError
- Test::Unit::PendedError
- Test::Unit::Pending
- Test::Unit::PendingHandler
- Test::Unit::Priority
- Test::Unit::Priority::Checker
- Test::Unit::Priority::ClassMethods
- Test::Unit::TestCase
- Test::Unit::TestCase::InternalData
- Test::Unit::TestCaseNotificationSupport
- Test::Unit::TestCaseOmissionSupport
- Test::Unit::TestCasePendingSupport
- Test::Unit::TestResult
- Test::Unit::TestResultErrorSupport
- Test::Unit::TestResultFailureSupport
- Test::Unit::TestResultNotificationSupport
- Test::Unit::TestResultOmissionSupport
- Test::Unit::TestResultPendingSupport
- Test::Unit::TestSuite
- Test::Unit::UI
- Test::Unit::UI::Console
- Test::Unit::UI::Console::ColorizedReadableDiffer
- Test::Unit::UI::Console::OutputLevel
- Test::Unit::UI::Console::TestRunner
- Test::Unit::UI::Emacs
- Test::Unit::UI::Emacs::TestRunner
- Test::Unit::UI::TestRunner
- Test::Unit::UI::TestRunnerMediator
- Test::Unit::UI::TestRunnerUtilities
- Test::Unit::UI::XML
- Test::Unit::UI::XML::TestRunner
- Test::Unit::Util
- Test::Unit::Util::BacktraceFilter
- Test::Unit::Util::MethodOwnerFinder
- Test::Unit::Util::Observable
- Test::Unit::Util::Output
- Test::Unit::Util::ProcWrapper

No matching classes.

# Test::Unit::TestResult

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`.

### Constants

CHANGED
FAULT
FINISHED
PASS_ASSERTION

### Attributes

assertion_count[R]
faults[R]
pass_count[R]
run_count[R]
stop_tag[RW]

### Public Class Methods

new() click to toggle source

Constructs a new, empty `TestResult`.

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 44
    def initialize
      @run_count, @pass_count, @assertion_count = 0, 0, 0
      @summary_generators = []
      @problem_checkers = []
      @faults = []
      @stop_tag = nil
      initialize_containers
    end

### Public Instance Methods

add_assertion() click to toggle source

Records an individual assertion.

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 65
    def add_assertion
      @assertion_count += 1
      notify_listeners(PASS_ASSERTION, self)
      notify_changed
    end

add_pass() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 60
    def add_pass
      @pass_count += 1
    end

add_run() click to toggle source

Records a test run.

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 54
    def add_run
      @run_count += 1
      notify_listeners(FINISHED, self)
      notify_changed
    end

pass_percentage() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 112
    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?() click to toggle source

Returns whether or not this `TestResult` represents successful completion.

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 108
    def passed?
      @problem_checkers.all? {|checker| not __send__(checker)}
    end

status() click to toggle source

Returnes a string that shows result status.

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 80
    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

stop() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 98
    def stop
      throw @stop_tag
    end

summary() click to toggle source

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

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 73
    def summary
      ["#{run_count} tests",
       "#{assertion_count} assertions",
       *@summary_generators.collect {|generator| __send__(generator)}].join(", ")
    end

to_s() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/testresult.rb, line 102
    def to_s
      summary
    end