RSpec-like doc format output in Elixir tests

When running RSpec tests you can pass a --format flag to rspec to format test output in a more verbose style. The default output looks like this.

1
....F.....*.....

If you pass --format documentation it will look more like this.

1
2
3
4
something
  does something that passes
  does something that fails (FAILED - 1)
  does something that is pending (PENDING: Not Yet Implemented)

I find this output really helpful. It helps to visualise the shape of the tests, and guides naming because you can see the visual hierarchy of how things fit together.

Elixir and ExUnit

You can achieve a very similar result to RSpec by passing --trace to mix test.

1
2
3
4
5
6
mix test --trace

TestApp.TimeDateHelper
  * test relative_format/1 single hour, multiple minutes (0.00ms)
  * test relative_format/1 greater than an hour (0.00ms)
  * test relative_format/1 less than a minute (0.00ms)

You can make this change across the whole test suite by changing the call to ExUnit.start/1 to include a trace option. This is usually in your test/test_helper.exs file.

1
ExUnit.start(trace: true)

Be aware though, this might not be what you want. From the ExUnit docs:

...sets ExUnit into trace mode, this sets :max_cases to 1 and prints each test case and test while running...

Setting trace: true will also set max_cases: 1 which will reduce the amount of tests that are run in parallel.

So this could slow down your test suite. Be careful!