O'Reilly logo

Metaprogramming Elixir by Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting Up Your Test Suite

Running Elixir tests is usually just a matter of running mix test in your project’s directory. If you need to test only a single file, Elixir makes it just as easy. Most of the exercises we’ve done so far have been single Elixir files, outside of a mix project. Let’s see how easy it is to test them by setting up a test suite for the while macro we built in Adding a while Loop to Elixir.

First things first: we need to create a test file. Launch your editor and create a while_test.exs file with the following code. Be sure to save it in the same directory as your while.exs file from the previous exercise.

macros/while_test_step1.exs
 
ExUnit.start
 
Code.require_file(​"while.exs"​, __DIR__)
 
 
defmodule​ WhileTest ​do ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required