123456789_123456789_123456789_123456789_123456789_

Class: Minitest::StatisticsReporter

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, Reporter, AbstractReporter, Mutex_m
Inherits: Minitest::Reporter
Defined in: lib/minitest.rb

Overview

A reporter that gathers statistics about a test run. Does not do any IO because meant to be used as a parent class for a reporter that does.

If you want to create an entirely different type of output (eg, CI, HTML, etc), this is the place to start.

Example:

class JenkinsCIReporter < StatisticsReporter
  def report
    super  # Needed to calculate some statistics

    print "<testsuite "
    print "tests='#{count}' "
    print "failures='#{failures}' "
    # Remaining XML...
  end
end

Class Method Summary

Instance Attribute Summary

Reporter - Inherited

#io

The IO used to report.

#options

Command-line options for this run.

AbstractReporter - Inherited

#passed?

Did this run pass?

Instance Method Summary

AbstractReporter - Inherited

#prerecord

About to start running a test.

#record

Output and record the result of the test.

#report

Outputs the summary of the run.

#start

Starts reporting on the run.

Constructor Details

.new(io = $stdout, options = {}) ⇒ StatisticsReporter

This method is for internal use only.
[ GitHub ]

  
# File 'lib/minitest.rb', line 766

def initialize io = $stdout, options = {} # :nodoc:
  super

  self.assertions = 0
  self.count      = 0
  self.results    = []
  self.start_time = nil
  self.total_time = nil
  self.failures   = nil
  self.errors     = nil
  self.skips      = nil
end

Instance Attribute Details

#assertions (rw)

Total number of assertions.

[ GitHub ]

  
# File 'lib/minitest.rb', line 726

attr_accessor :assertions

#count (rw)

Total number of test cases.

[ GitHub ]

  
# File 'lib/minitest.rb', line 731

attr_accessor :count

#errors (rw)

Total number of tests that erred.

[ GitHub ]

  
# File 'lib/minitest.rb', line 759

attr_accessor :errors

#failures (rw)

Total number of tests that failed.

[ GitHub ]

  
# File 'lib/minitest.rb', line 754

attr_accessor :failures

#passed?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/minitest.rb', line 779

def passed? # :nodoc:
  results.all?(&:skipped?)
end

#results (rw)

An Array of test cases that failed or were skipped.

[ GitHub ]

  
# File 'lib/minitest.rb', line 736

attr_accessor :results

#skips (rw)

Total number of tests that where skipped.

[ GitHub ]

  
# File 'lib/minitest.rb', line 764

attr_accessor :skips

#start_time (rw)

Time the test run started. If available, the monotonic clock is used and this is a Float, otherwise it’s an instance of Time.

[ GitHub ]

  
# File 'lib/minitest.rb', line 743

attr_accessor :start_time

#total_time (rw)

Test run time. If available, the monotonic clock is used and this is a Float, otherwise it’s an instance of Time.

[ GitHub ]

  
# File 'lib/minitest.rb', line 749

attr_accessor :total_time

Instance Method Details

#record(result)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/minitest.rb', line 787

def record result # :nodoc:
  self.count += 1
  self.assertions += result.assertions

  results << result if not result.passed? or result.skipped?
end

#report

Report on the tracked statistics.

[ GitHub ]

  
# File 'lib/minitest.rb', line 797

def report
  aggregate = results.group_by { |r| r.failure.class }
  aggregate.default = [] # dumb. group_by should provide this

  self.total_time = Minitest.clock_time - start_time
  self.failures   = aggregate[Assertion].size
  self.errors     = aggregate[UnexpectedError].size
  self.skips      = aggregate[Skip].size
end

#start

This method is for internal use only.
[ GitHub ]

  
# File 'lib/minitest.rb', line 783

def start # :nodoc:
  self.start_time = Minitest.clock_time
end