Class: Megatest::Reporters::SimpleReporter

Inherits:
AbstractReporter show all
Defined in:
lib/megatest/reporters.rb

Direct Known Subclasses

VerboseReporter

Instance Method Summary collapse

Methods inherited from AbstractReporter

#before_test_case, #initialize

Constructor Details

This class inherits a constructor from Megatest::Reporters::AbstractReporter

Instance Method Details

#after_test_case(_queue, _test_case, result) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/megatest/reporters.rb', line 80

def after_test_case(_queue, _test_case, result)
  if result.skipped?
    @out.print(@out.yellow("S"))
  elsif result.retried?
    @out.print(@out.yellow("R"))
  elsif result.error?
    @out.print(@out.red("E"))
  elsif result.failed?
    @out.print(@out.red("F"))
  else
    @out.print(@out.green("."))
  end
end

#ms(duration) ⇒ Object



148
149
150
# File 'lib/megatest/reporters.rb', line 148

def ms(duration)
  format("%.1fms", duration * 1000.0)
end

#s(duration) ⇒ Object



144
145
146
# File 'lib/megatest/reporters.rb', line 144

def s(duration)
  format("%.2fs", duration)
end

#start(_executor, queue) ⇒ Object



73
74
75
76
77
78
# File 'lib/megatest/reporters.rb', line 73

def start(_executor, queue)
  @out.print("Running #{queue.size} test cases with --seed #{@config.seed}")
  @out.print(" in #{@config.jobs_count} processes") if @config.jobs_count > 1
  @out.puts
  @out.puts
end

#summary(executor, queue, summary) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/megatest/reporters.rb', line 94

def summary(executor, queue, summary)
  @out.puts
  @out.puts

  failures = summary.failures.reject(&:skipped?)
  unless failures.empty?
    failures = failures.sort_by(&:test_id)
    failures.each_with_index do |result, index|
      @out.print "  #{index + 1}) "
      @out.puts render_failure(result)
      @out.puts
    end
  end

  # In case of failure we'd rather not print slow tests
  # as it would blur the output.
  if queue.success? && !summary.results.empty?
    sorted_results = summary.results.sort_by(&:duration)
    size = sorted_results.size
    average = sorted_results.sum(&:duration) / size
    median = sorted_results[size / 2].duration
    p90 = sorted_results[(size * 0.9).to_i].duration
    p99 = sorted_results[(size * 0.99).to_i].duration

    @out.puts "Finished in #{s(executor.wall_time.to_f)}, average: #{ms(average)}, median: #{ms(median)}, p90: #{ms(p90)}, p99: #{ms(p99)}"
    cutoff = p90 * 10
    slowest_tests = sorted_results.last(5).select { |r| r.duration > cutoff }
    unless slowest_tests.empty?
      @out.puts "Slowest tests:"
      slowest_tests.reverse_each do |result|
        duration_string = ms(result.duration).rjust(10, " ")
        @out.puts " - #{duration_string} #{@out.yellow(result.test_id)} @ #{@out.cyan(Megatest.relative_path(result.test_location))}"
      end
      @out.puts ""
    end
  end

  @out.print format(
    "Ran %d cases, %d assertions, %d failures, %d errors, %d retries, %d skips",
    summary.runs_count,
    summary.assertions_count,
    summary.failures_count,
    summary.errors_count,
    summary.retries_count,
    summary.skips_count,
  )
  @out.print(" in #{@config.jobs_count} processes") if @config.jobs_count > 1
  @out.puts
end