Introduction to Testing
Oban Pro provides advanced helpers that make it easy to test workers, drain queues reliably, supervise test instances, and make assertions about enqeueud jobs. These are the exact same helpers that Pro uses for testing internally!
Configure for Testing
Testing Pro features such as
Workflow workers only works when
:manual mode. If you're running with
:inline mode, or don't have
testing configured at all, update your test config:
# test.exs config :my_app, Oban, testing: :manual
Now you're ready to import the advanced test helpers.
Setup Testing Helpers
All testing helpers are provided by
Oban.Pro.Testing, a drop-in replacement
Oban.Testing with additional functions tailored toward integration testing
and Pro modules.
The most convenient way to use the helpers is to
use the module within your
defmodule MyApp.Case do use ExUnit.CaseTemplate using do quote do use Oban.Pro.Testing, repo: MyApp.Repo end end end
Alternatively, you can
use the testing module in individual tests if you'd
prefer not to include helpers in every test.
defmodule MyApp.WorkerTest do use MyApp.Case, async: true use Oban.Pro.Testing, repo: MyApp.Repo end
Oban.Pro.Testing requires the
repo option because it's injected into
many of the generated helpers. Other repo-specific options like
log are also supported:
using do quote do use Oban.Pro.Testing, repo: MyApp.Repo, prefix: "private", log: :debug end end
Oban.Pro.Testing docs for complete options and usage.
Understanding the Types of Helpers
Much like the layers of a traditional testing pyramid,
stratifies into unit, integration, and acceptance helpers:
Unit—execute jobs locally, without touching the database. These helpers start with a
Integration—insert jobs into the database and execute them inline. These helpers start with
Acceptance—run Oban as a supervised process that autonomously runs queues and plugins normally. This is simplified with the
Each layer of testing has its place within a complex application's test suite. Let's start with unit testing in Testing Pro Workers.