Claude-elixir-phoenix testing
Elixir testing patterns — ExUnit, Mox, factories, LiveView test helpers. Use when working on *_test.exs, test/support/, factory files, or fixing test failures.
install
source · Clone the upstream repo
git clone https://github.com/oliver-kriska/claude-elixir-phoenix
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/oliver-kriska/claude-elixir-phoenix "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/elixir-phoenix/skills/testing" ~/.claude/skills/oliver-kriska-claude-elixir-phoenix-testing && rm -rf "$T"
manifest:
plugins/elixir-phoenix/skills/testing/SKILL.mdsource content
Elixir Testing Reference
Quick reference for Elixir testing patterns.
Iron Laws — Never Violate These
- ASYNC BY DEFAULT — Use
unless tests modify global stateasync: true - SANDBOX ISOLATION — All database tests use Ecto.Adapters.SQL.Sandbox
- MOCK ONLY AT BOUNDARIES — Never mock database, internal modules, or stdlib
- BEHAVIOURS AS CONTRACTS — All mocks must implement a defined
behaviour@callback - BUILD BY DEFAULT — Use
in factories;build/2
only when DB neededinsert/2 - NO PROCESS.SLEEP — Use
with timeout for async operationsassert_receive - VERIFY_ON_EXIT! — Always call in Mox tests setup
- FACTORIES MATCH SCHEMA REQUIRED FIELDS — Factory definitions must include all fields that have
in the schema changeset. Missing fields cause cascading test failuresvalidate_required
Quick Decisions
Which Test Case?
| Testing | Use |
|---|---|
| Controller/API | |
| Context/Schema | |
| LiveView | + |
| Pure logic | |
When to use async: true?
- ✅ Pure functions, no shared state
- ✅ Database tests with Sandbox (PostgreSQL)
- ❌ Tests modifying
Application.put_env - ❌ Tests using Mox global mode
Mock or not?
- ✅ Mock: External APIs, email services, file storage
- ❌ Don't mock: Database, internal modules, stdlib
build() or insert()?
- Use
by default for speedbuild() - Use
only when you need DB ID, constraints, or persisted associationsinsert()
Quick Patterns
# Setup chain setup [:create_user, :authenticate] # Pattern matching assertion assert {:ok, %User{name: name}} = create_user(attrs) # Async message assertion assert_receive {:user_created, _}, 5000 # Mox setup setup :verify_on_exit! expect(MockAPI, :call, fn _ -> {:ok, "data"} end) # LiveView async html = render_async(view) # MUST call for assign_async
Common Anti-patterns
| Wrong | Right |
|---|---|
| |
in factory | in factory |
with | |
| Mock internal modules | Test through public API |
References
For detailed patterns, see:
- Setup, assertions, tags${CLAUDE_SKILL_DIR}/references/exunit-patterns.md
- Behaviours, expect/stub, async${CLAUDE_SKILL_DIR}/references/mox-patterns.md
- Forms, async, uploads${CLAUDE_SKILL_DIR}/references/liveview-testing.md
- ExMachina, sequences, traits${CLAUDE_SKILL_DIR}/references/factory-patterns.md