Class: Test::Unit::TestResult

### Home Classes Methods

### In Files

- lib/test/unit/testresult.rb

### Parent

Object

### Methods

- ::new
- #add_assertion
- #add_pass
- #add_run
- #pass_percentage
- #passed?
- #status
- #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

- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- Test::Unit::Assertions
- Test::Unit::Attribute
- Test::Unit::Attribute::BaseClassMethods
- Test::Unit::Attribute::ClassMethods
- Test::Unit::Attribute::StringifyKeyHash
- Test::Unit::AttributeMatcher
- Test::Unit::AutoRunner
- 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::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::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
- Object

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]

### Public Class Methods

new() click to toggle source

Constructs a new, empty TestResult.

    # 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

### Public Instance Methods

add_assertion() click to toggle source

Records an individual assertion.

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

add_pass() click to toggle source

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

add_run() click to toggle source

Records a test run.

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

pass_percentage() click to toggle source

    # 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?() click to toggle source

Returns whether or not this TestResult represents successful completion.

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

status() click to toggle source

Returnes a string that shows result status.

    # 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() click to toggle source

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

    # 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() click to toggle source

    # File lib/test/unit/testresult.rb, line 95
    def to_s
      summary
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.