Unit testing
In this section, we'll explore how to create tests in Elixir, using ExUnit. We'll split it between tests that exercise functions with and without side-effects, since we have different approaches for each type of function. Let's begin by the simpler case: testing functions that don't have side-effects.
Testing functions without side-effects
A unit test exercises a function from a certain module of the application. We might have more than one test exercising the same function (with different inputs, for instance). Let's begin by creating a simple test, which will allow us to analyze ExUnit in detail. We'll be creating the tests for the is_valid_path?
function, which belongs to the ElixirDrip.Storage.Media
module. For context, we present its implementation as follows:
$ cat apps/elixir_drip/lib/elixir_drip/storage/media.ex defmodule ElixirDrip.Storage.Media do # ... def is_valid_path?(path) when is_binary(path) do valid? = String.starts_with?(path, "$") && !String...