> For the complete documentation index, see [llms.txt](https://elixir.petrolidas.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://elixir.petrolidas.com/bits-and-pieces/run-tests-automatically-on-save.md).

# Run tests automatically on save

Reported from [dev.to](https://dev.to/petros/run-tests-automatically-on-save-1bcm)

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](https://hex.pm/) package:

[mix\_test\_watch](https://hex.pm/packages/mix_test_watch)

### Install the dependency

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

### Configure it in your project

```elixir
# 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:

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

### Example

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

<figure><img src="/files/6HWsBrPTbacGdOltxAhW" alt=""><figcaption><p>Saving a file in VS Code, runs the tests automatically in the terminal below.</p></figcaption></figure>

Enjoy!

{% hint style="info" %}
Do you have feedback or questions about this? [Email me](mailto:petros@hey.com).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://elixir.petrolidas.com/bits-and-pieces/run-tests-automatically-on-save.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
