10 December 2017
focus: true can be used to just run a subset of specs. To achieve something similar with Elixir, there are two main approaches that I have used.
You can specify the test’s line number from the command line. Here’s an example:
$ mix test test/address_builder/au/import/gnaf_importer_test.exs:41
This will run just the test on
line 41 of the file.
You can use tags to mark a test (or multiple tests) to be run. Here’s an example:
@tag :focus test "with mixed case" do assert StringUtil.titleize("weLLington") == "Wellington" end
You can then run your test with the
$ mix test --only focus
It’s also compatible with the mix_test_watch package, so any edits will be retested straight away.
$ mix test.watch --only focus