Minitest—how to see the failed tests
Asked Answered
C

2

5

I'm working on an application with 731 tests, and if 6 fail, I have to scroll through 731 lines to try and spot each failure so I can fix the problems.

Is there a way for minitest to print all the failed tests at the bottom? Or anything that would help me identify which tests are failing?

Carbamidine answered 21/8, 2020 at 5:46 Comment(0)
R
6

I am often using a large suite of tests, with some tests having fairly verbose diagnostic output. So I redirect STDOUT and STDERR to a log file, then grep the file for errors like so:

bundle exec rake test:all &> test.log
grep -P -i -C3 'error|fail' test.log

Example output:

...
Failure:
FooBarTest#test_foo [/path/to/foo_bar_test.rb:64]:
Expected: 3
  Actual: 4
...
Finished in 3.945161s, 13.9411 runs/s, 162.4775 assertions/s.
55 runs, 641 assertions, 1 failures, 0 errors, 0 skips

Here, grep is run with options:
-P : use Perl regular expressions,
-i : case insensitive,
-C3 : print 3 lines above and 3 lines below the matching line, to provide more context of the failed tests.

Sometimes I then follow this up and look at the test log file in the editor for details on diagnostic messages, etc. But the grep summary gives me most of the context I need in the majority of the cases.

Recur answered 21/8, 2020 at 15:25 Comment(0)
M
0

The failed test output at the end of the run is available when using the print_failure_summary option with the minitest-reporters gem:

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new(print_failure_summary: true)
Moulder answered 2/8, 2024 at 16:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.