DEV Community

Petros Amoiridis
Petros Amoiridis

Posted on

Run tests automatically on save

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 hex package:

mix_test_watch

Install the dependency

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

Configure it in your project

# config/config.exs
import Config

if config_env() == :dev do
  config :mix_test_watch,
    clear: true
end
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Example

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

Run tests on save in VS Code

Enjoy!

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay