Search⌘ K
AI Features

The Final Test for Our Quizzes

Explore how to effectively test Elixir quizzes by managing their lifecycle and scheduling using OTP. Understand how to handle time boundaries, capture logs, and verify notifications to ensure your quiz processes work as expected from start to termination. This lesson guides you through setting up tests that simulate real-world quiz execution and validate OTP integration.

Once the additional infrastructure of the scheduling notification is in place, our tests will be easier to write.

Let’s dive right in. We’ll write this in /test/proctor_test.exs:

C++
defmodule ProctorTest do
use ExUnit.Case
alias Mastery.Examples.Math
alias Mastery.Boundary.QuizSession
@moduletag capture_log: true

We do the typical setup ceremony with one addition. With the module attribute @capture_log, we turn on the logging capture to avoid adding noisy logging to our test cases.

The rest of this test case will deal with time. Boundaries are powerful, but all of that power has a cost—the ceremony of dealing with time. This test exists specifically to walk our code through its entire lifecycle, step by step. We’ll do all of this work in a single test to keep things simple to read and maintain in the future.

Our setup to start the quiz

The first step is to start up the quiz, ...