Class: Minitest::StatisticsReporter

Inherits:
Reporter show all
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

Direct Known Subclasses

SummaryReporter

Instance Attribute Summary collapse

Attributes inherited from Reporter

#io, #options

Instance Method Summary collapse

Methods inherited from AbstractReporter

#prerecord, #synchronize

Constructor Details

#initialize(io = $stdout, options = {}) ⇒ StatisticsReporter

:nodoc:


839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'lib/minitest.rb', line 839

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.warnings   = nil
  self.skips      = nil
end

Instance Attribute Details

#assertionsObject

Total number of assertions.


794
795
796
# File 'lib/minitest.rb', line 794

def assertions
  @assertions
end

#countObject

Total number of test cases.


799
800
801
# File 'lib/minitest.rb', line 799

def count
  @count
end

#errorsObject

Total number of tests that erred.


827
828
829
# File 'lib/minitest.rb', line 827

def errors
  @errors
end

#failuresObject

Total number of tests that failed.


822
823
824
# File 'lib/minitest.rb', line 822

def failures
  @failures
end

#resultsObject

An Array of test cases that failed or were skipped.


804
805
806
# File 'lib/minitest.rb', line 804

def results
  @results
end

#skipsObject

Total number of tests that where skipped.


837
838
839
# File 'lib/minitest.rb', line 837

def skips
  @skips
end

#start_timeObject

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


811
812
813
# File 'lib/minitest.rb', line 811

def start_time
  @start_time
end

#total_timeObject

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


817
818
819
# File 'lib/minitest.rb', line 817

def total_time
  @total_time
end

#warningsObject

Total number of tests that warned.


832
833
834
# File 'lib/minitest.rb', line 832

def warnings
  @warnings
end

Instance Method Details

#passed?Boolean

:nodoc:

Returns:

  • (Boolean)

853
854
855
# File 'lib/minitest.rb', line 853

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

#record(result) ⇒ Object

:nodoc:


861
862
863
864
865
866
# File 'lib/minitest.rb', line 861

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

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

#reportObject

Report on the tracked statistics.


871
872
873
874
875
876
877
878
879
880
# File 'lib/minitest.rb', line 871

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.warnings   = aggregate[UnexpectedWarning].size
  self.skips      = aggregate[Skip].size
end

#startObject

:nodoc:


857
858
859
# File 'lib/minitest.rb', line 857

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