Skip to content

Commit ba04ffb

Browse files
feat: add test summary to minitest
1 parent 55015dc commit ba04ffb

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

ruby/lib/minitest/queue/build_status_reporter.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def report
153153
puts
154154

155155
errors = error_reports
156-
puts errors
156+
if errors.any?
157+
pretty_print_summary(errors)
158+
pretty_print_failures(errors)
159+
end
157160

158161
build.worker_errors.to_a.sort.each do |worker_id, error|
159162
puts red("Worker #{worker_id } crashed")
@@ -224,6 +227,37 @@ def write_flaky_tests_file(file)
224227

225228
attr_reader :build, :supervisor
226229

230+
def pretty_print_summary(errors)
231+
test_paths = errors.map(&:test_file).compact
232+
return unless test_paths.any?
233+
234+
file_counts = test_paths.each_with_object(Hash.new(0)) { |path, counts| counts[path] += 1 }
235+
236+
puts "\n" + "=" * 80
237+
puts "FAILED TESTS SUMMARY:"
238+
puts "=" * 80
239+
file_counts.sort_by { |path, _| path }.each do |path, count|
240+
relative_path = Minitest::Queue.relative_path(path)
241+
if count == 1
242+
puts " #{relative_path}"
243+
else
244+
puts " #{relative_path} (#{count} failures)"
245+
end
246+
end
247+
puts "=" * 80
248+
end
249+
250+
def pretty_print_failures(errors)
251+
errors.each_with_index do |error, index|
252+
puts "\n" + "-" * 80
253+
puts "Error #{index + 1} of #{errors.size}"
254+
puts "-" * 80
255+
puts error
256+
end
257+
258+
puts "=" * 80
259+
end
260+
227261
def timed_out?
228262
supervisor.time_left.to_i <= 0
229263
end

ruby/test/integration/minitest_redis_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,40 @@ def test_redis_reporter
954954
Ran 7 tests, 8 assertions, 2 failures, 1 errors, 1 skips, 4 requeues in X.XXs (aggregated)
955955
956956
957+
958+
================================================================================
959+
FAILED TESTS SUMMARY:
960+
================================================================================
961+
test/dummy_test.rb (3 failures)
962+
================================================================================
963+
964+
--------------------------------------------------------------------------------
965+
Error 1 of 3
966+
--------------------------------------------------------------------------------
957967
FAIL ATest#test_bar
958968
Expected false to be truthy.
959969
test/dummy_test.rb:10:in `test_bar'
960970
971+
972+
--------------------------------------------------------------------------------
973+
Error 2 of 3
974+
--------------------------------------------------------------------------------
961975
FAIL ATest#test_flaky_fails_retry
962976
Expected false to be truthy.
963977
test/dummy_test.rb:23:in `test_flaky_fails_retry'
964978
979+
980+
--------------------------------------------------------------------------------
981+
Error 3 of 3
982+
--------------------------------------------------------------------------------
965983
ERROR BTest#test_bar
984+
Minitest::UnexpectedError: TypeError: String can't be coerced into Integer
985+
test/dummy_test.rb:37:in `+'
986+
test/dummy_test.rb:37:in `test_bar'
987+
test/dummy_test.rb:37:in `+'
988+
test/dummy_test.rb:37:in `test_bar'
989+
990+
================================================================================
966991
END
967992
assert_includes output, expected_output
968993
end

0 commit comments

Comments
 (0)