Skip to content

Instantly share code, notes, and snippets.

@ktec
Created February 19, 2019 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktec/e78469638bd390309f0db3f883ed94b7 to your computer and use it in GitHub Desktop.
Save ktec/e78469638bd390309f0db3f883ed94b7 to your computer and use it in GitHub Desktop.
Elixir Test Runner - Test Driven Development with Entr

Install entr:

https://github.com/clibs/entr

Add this to .bashrc

elixir_test() {
  if [[ $# -eq 0 ]] ; then
    find . -name '*.ex' -o \
           -name '*.exs' -o \
           -name '*.eex' | \
           entr mix test
  else
    find . -name '*.ex' -o \
           -name '*.exs' -o \
           -name '*.eex' | \
           entr mix test --include $1 --exclude test
  fi
}

From command line, in an elixir project:

$ elixir_test

This will run the tests whenever file change event is detected.

For more focused testing, you can run this:

$ elixir_test focus

And update your tests like this:

  describe "using entr for test driven development" do
    @tag :focus
    test "only this test will be run" do
      assert true
    end

    test "this test will not be run" do
      assert true
    end
  end

Happy coding...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment