Elixir
  • My Elixir journey
  • Why functional programming?
  • Exhort
    • 🗓️Day 22
    • 🗓️Day 21
    • 🗓️Day 20
    • 🗓️Day 19
    • 🗓️Day 18
    • 🗓️Day 17
    • 🗓️Day 16
    • 🗓️Day 15
    • 🗓️Day 14
  • Bits and pieces
    • Clean mix dependencies
    • Run tests automatically on save
    • Run tests and stop on first failure
    • How to remove Tailwind from a Phoenix project
Powered by GitBook
  1. Bits and pieces

Run tests automatically on save

Running your tests automatically every time you save helps a lot with languages like Elixir.

PreviousClean mix dependenciesNextRun tests and stop on first failure

Last updated 2 years ago

Reported from

I was looking for a solution to run tests automatically every time I save any changes. The best way so far for me is the following package:

Install the dependency

# mix.exs (v1.13)
def deps do
  [
    {:mix_test_watch, "~> 1.0", only: :dev}
  ]
end

Configure it in your project

# config/config.exs
import Config
​
if config_env() == :dev do
  config :mix_test_watch,
    clear: true
end

The clear: true option means that the screen will clear every time tests run. This is useful because it is easier to scroll back to the top of the most recent test run.

Start watching for changes

In your terminal or within a VS Code terminal, this works great:

mix test.watch --seed 0 --max-failures 1 --include pending

Example

Here's an example of how this looks in VS Code:

Enjoy!

Do you have feedback or questions about this? .

dev.to
hex
mix_test_watch
Email me
Saving a file in VS Code, runs the tests automatically in the terminal below.