Zuhaib

Automatically Trigger Dart Test Runs On File Changes

THURSDAY JUNE 26 2025 - 1 MIN

Automatically Trigger Dart Test Runs On File Changes

Jest has us spoiled

In the JavaScript world I run jest --watch and forget about it. Change a file and the tests rerun before I can switch windows. It makes TDD painless.

Flutter? Crickets

flutter test is fine but it has no built-in watcher. I searched for plug-ins, flags, secret env vars – nothing. There are a handful of community tools but most are abandoned.

Remember the spec package?

For a while spec wrapped the test runner and watched your files. Sadly it stopped working after the Dart 3 upgrade and the repo has been dormant.

I even tried Nodemon

nodemon --exec "flutter test" --ext dart almost works, until it doesn't. It gets confused by generated files, spams multiple runs and never exits cleanly on Ctrl-C. After the third flaky loop I gave up.

Enter fswatch

fswatch is a tiny cross-platform file watcher written in C. Homebrew users can grab it with:

brew install fswatch

Then add a shell alias. I dropped this in my ~/.zshrc:

alias dtest='fswatch -or lib test | xargs -n1 -I{} flutter test'

Breakdown:

  • fswatch -or lib test – recursively watch the lib and test folders and emit one event (-o) each time something changes.
  • xargs -n1 -I{} flutter test – for every event run one flutter test run.

Open a new terminal tab, run dtest, start coding and watch the green ticks fly. Zero config, instant feedback.

That's it. No more manual flutter test spam, no flaky wrappers. Just a simple watcher that does one job and does it well.


For suggestions and queries, just contact me.

Zuhaib Ahmad © 2025