0PricingLogin
Elixir & Phoenix: Scalable Backend Development · Lesson

Unit Testing with ExUnit

Write fast and reliable unit tests for your Elixir modules and functions using the built-in ExUnit framework.

Intro to ExUnit

Welcome to unit testing with ExUnit! ExUnit is Elixir's built-in testing framework, designed to help you write reliable and maintainable code.

Unit tests focus on small, isolated parts of your code, like individual functions or modules. They ensure each component works as expected, giving you confidence as your application grows.

Your First ExUnit Test

Elixir test files typically end with _test.exs and are placed in a test/ directory. Inside, you use ExUnit.Case to bring in testing functionalities.

A test block starts with test "description" do ... end. Here's a simple example:

defmodule MyMath do
  def add(a, b), do: a + b
end

defmodule MyMathTest do
  use ExUnit.Case, async: true

  test "adds two numbers correctly" do
    assert MyMath.add(1, 2) == 3
  end
end

All lessons in this course

  1. Unit Testing with ExUnit
  2. Integration Testing Phoenix Applications
  3. Mocking, Stubs, and Test Data
  4. Property-Based Testing with StreamData
← Back to Elixir & Phoenix: Scalable Backend Development