ExUnit show only failing files

With ExUnit is there a way to only show files that have a failing test? Ideally ExUnit would run all my tests but fail each file as soon as there is a failing test in that file.

My use case is that when I make a large change to the system, I want to focus on test failures one file at a time, but right now there is not an easy way to find files with test failures without running all my tests (in an umbrella project) and then scrolling up to see which tests failed, and checking what files there are in. Since test failures often have very large output it is difficult to find more than one failing file in this way.

I’m not sure what you mean by “failing fies”, as tests are failing and not files, but do you know about the --stale option? It runs only those tests, that are affected by the changes you made snce the last run.

1 Like

Are you thinking of something like rspec’s --fail-fast option?

1 Like

I do know about the --stale option but it isn’t as useful for me since I want to re-run the tests for just one file in my editor and not re-run all the tests that may have been impacted by a change.

I’m thinking of something similar, but just get running until the first failing test in each test file (as a speed optimization).

Looking at the ExUnit docs, I think I can accomplish what I want (sans stopping after first failed test in a file) with an ExUnit formatter. I think I’ll give that a try.

Okay, I’ve created a simple ExUnit formatter that gives me the output that I want https://github.com/axelson/ex_unit_file_formatter

Example output:

==> my_app

Failed Files:
1: /Users/jason/dev/my_app/apps/web_interface/test/controllers/internal_api/v1/page_controller_test.exs
==> parser

Failed Files:
9: /Users/jason/dev/my_app/apps/parser/test/parser_test.exs
5: /Users/jason/dev/my_app/apps/parser/test/parser_info_test.exs
1: /Users/jason/dev/my_app/apps/parser/test/file_parser_test.exs
==> ftp_handler

Where the number to the left of the filename represents the number of failed tests in that file. This condensed output is especially handy if you have an umbrella application with many applications.

5 Likes