Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Last active July 1, 2020 13:26
Show Gist options
  • Save atomkirk/8de8ffaeff370019ebfd96c31413b719 to your computer and use it in GitHub Desktop.
Save atomkirk/8de8ffaeff370019ebfd96c31413b719 to your computer and use it in GitHub Desktop.
Run Elixir tests on VSCode save

A really great workflow is to write your test first (TDD anyone?), run the test to verify it fails (eliminate false positive) and then write the implementation. I've included a runOnSave setting to run a test file anytime it is saved and, second, to run any failed tests as soon as any other elixir file is saved.

So, you write the test, save, it fails. You write Elixir code, save, it still fails. You keep writing Elixir code and saving until it passes.

This is obviously cool. But one thing that is particularly cool is that while you are writing the implementation, you often want to peek at values and experiment with code. Well, thats easy! Just write the code, IO.inspect it and then save! You'll instantly get feedback on your experiment using your test data. It's like writing your code in a repl. Except it's tested. And in version control.

"runOnSave.commands": [
{
"match": ".*\\.exs$",
"command": "(cd elixir && mix test ${file})",
"runIn": "terminal"
},
{
"match": ".*\\.ex$",
"command": "(cd elixir && mix test --failed)",
"runIn": "terminal"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment