Mirror318
Mirror318

Reputation: 12683

Minitest—how to see the failed tests

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?

Upvotes: 5

Views: 1452

Answers (2)

littleforest
littleforest

Reputation: 2245

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)

Upvotes: 1

Timur Shtatland
Timur Shtatland

Reputation: 12347

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.

Upvotes: 6

Related Questions