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:



884
885
886
887
888
889
890
891
892
893
894
895
896
# File 'lib/minitest.rb', line 884

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

#assertions ⇒ Object

Total number of assertions.



839
840
841
# File 'lib/minitest.rb', line 839

def assertions
  @assertions
end

#count ⇒ Object

Total number of test cases.



844
845
846
# File 'lib/minitest.rb', line 844

def count
  @count
end

#errors ⇒ Object

Total number of tests that erred.



872
873
874
# File 'lib/minitest.rb', line 872

def errors
  @errors
end

#failures ⇒ Object

Total number of tests that failed.



867
868
869
# File 'lib/minitest.rb', line 867

def failures
  @failures
end

#results ⇒ Object

An Array of test cases that failed or were skipped.



849
850
851
# File 'lib/minitest.rb', line 849

def results
  @results
end

#skips ⇒ Object

Total number of tests that where skipped.



882
883
884
# File 'lib/minitest.rb', line 882

def skips
  @skips
end

#start_time ⇒ Object

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



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

def start_time
  @start_time
end

#total_time ⇒ Object

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



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

def total_time
  @total_time
end

#warnings ⇒ Object

Total number of tests that warned.



877
878
879
# File 'lib/minitest.rb', line 877

def warnings
  @warnings
end

Instance Method Details

#passed? ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


898
899
900
# File 'lib/minitest.rb', line 898

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

#record(result) ⇒ Object

:nodoc:



906
907
908
909
910
911
# File 'lib/minitest.rb', line 906

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

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

#report ⇒ Object

Report on the tracked statistics.



916
917
918
919
920
921
922
923
924
925
# File 'lib/minitest.rb', line 916

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

#start ⇒ Object

:nodoc:



902
903
904
# File 'lib/minitest.rb', line 902

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