In my previous note Shorter feedback loops with Elixir tests I already described how to run tests in Elixir, where it only runs the failed tests. Below is what I put in my mix.exs
file to have faster feedback loops when testing:
defp aliases do
[
...
"test.failed": ["test --failed --max-failures 1"],
]
end
# Make sure the alias runs in the test MIX_ENV environment.
def cli do
[preferred_envs: ["test.failed": :test]]
end
This will create a new alias test.failed
that will run only the failed tests and stop after the first failure. This is useful when you are working on a specific test and you want to run it quickly without running all the tests.
In Ruby, you have the --fail-fast
flag, which stops running the test suite at the first failed test. Convenient to get shorter feedback loops, with a long running test suite.
In Elixir, you can achieve the same with:
mix test --max-failures 1
And then when a test fails, you fix it, and make sure that it works with:
mix test --failed
That makes for shorter feedback loops!
With Zig, I usually run zig build test
to run all the tests. However, sometimes, I need to run a single test, and that option is not available through the build
command.
In this case, I learned you can use the zig test
command along with the --test-filter
option.
For example, to test a single test named “lexer initialization” located in src/lexer/lexer.zig
, you can run zig test --test-filter “lexer initialization” src/lexer/lexer.zig
. It’s worth noting that the test filter doesn’t have to be the full name of the test to be able to find it.