— Jul 25, 2015
Update: This is now built into Elixir.
Recently I’ve been playing with Elixir in my spare time. It’s a dynamic, functional programming language built atop the Erlang virtual machine. I try to practice TDD when writing software to encourage flexible designs. One habit of mine is writing out many tests early about how I imagine a thing to work. Of course all these tests fail initially which can be overwhelming when run together. It’s much more desirable to focus on one failing test at a time throughout the red, green, refactor process.
mix script is a neat little tool to create, manage, and test your Elixir projects.
mix runs tests with the built-in
This module is intentionally designed to be very basic, providing a small API for testing your programs.
While the ability to mark tests as pending is not immediately clear, it’s easy to pull off.
This construct in Elixir is used for:
In ExUnit the
@tag annotation can be used to add metadata to tests.
If you have used RSpec, this is very similar to the hash passed as an optional second argument to
So we’ll tag our ExUnit tests and skip them until we’re ready to test the interface!
To run the test suite and skip these tagged tests, we can provide the
--exclude option to
To take things one step further, it would be nice if we didn’t have to use a command line option every time we wanted to skip tests.
We can accomplish this by configuring ExUnit to exclude the
:skip tag everytime.
test/test_helper.exs in your Elixir project and add the following:
Now every time you run your test suite “skipped” tests are excluded! 💫
I’m having a lot of fun with Elixir. Do you have any other invaluable tricks? Please share!