本文へ移動
cccskills
無料GitHub で公開

testing

Write or repair Elixir tests with ExUnit, sandbox isolation, async; Use for test files, test setup, or failing/flaky…

インストール方法を見る

含まれるファイル(5)

  • SKILL.md2.8 KB
  • references/exunit-patterns.md4.8 KB
  • references/factory-patterns.md2.9 KB
  • references/liveview-testing.md2.4 KB
  • references/mox-patterns.md2.0 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Elixir Testing Reference

Ash projects: Use DataCase with Ash.Test helpers; test actions via domain code interfaces, not direct Repo calls. See ash-framework skill.

Quick reference for Elixir testing patterns.

Iron Laws — Never Violate These

  1. ASYNC BY DEFAULT — Use async: true unless tests modify global state
  2. SANDBOX ISOLATION — All database tests use Ecto.Adapters.SQL.Sandbox
  3. MOCK ONLY AT BOUNDARIES — Never mock database, internal modules, or stdlib
  4. BEHAVIOURS AS CONTRACTS — All mocks must implement a defined @callback behaviour
  5. BUILD BY DEFAULT — Use build/2 in factories; insert/2 only when DB needed
  6. NO PROCESS.SLEEP — Use assert_receive with timeout for async operations
  7. VERIFY_ON_EXIT! — Always call in Mox tests setup
  8. FACTORIES MATCH SCHEMA REQUIRED FIELDS — Factory definitions must include all fields that have validate_required in the schema changeset. Missing fields cause cascading test failures

Quick Decisions

Which Test Case?

TestingUse
Controller/APIuse MyAppWeb.ConnCase
Context/Schemause MyApp.DataCase
LiveViewuse MyAppWeb.ConnCase + import Phoenix.LiveViewTest
Pure logicuse ExUnit.Case, async: true

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 build() by default for speed
  • Use insert() only when you need DB ID, constraints, or persisted associations

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

WrongRight
Process.sleep(100)assert_receive {:done, _}, 5000
insert(:user) in factorybuild(:user) in factory
async: true with set_mox_global()async: false
Mock internal modulesTest through public API

References

For detailed patterns, see:

  • references/exunit-patterns.md - Setup, assertions, tags
  • references/mox-patterns.md - Behaviours, expect/stub, async
  • references/liveview-testing.md - Forms, async, uploads
  • references/factory-patterns.md - ExMachina, sequences, traits

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Ash Framework — resources, actions, policies, aggregates; Use when generating resources via mix ash.codegen, editing…

日本語の概要は準備中です。原文の説明を表示しています。

oliver-kriska/claude-elixir-phoenix5652026年10月6日 更新

Ash Framework — resources, actions, policies, aggregates, calculations, AshPhoenix.Form, LiveView, migrations. Use when generating resources via mix ash.codegen, editing changes, checks, types, validations, or domain code interfaces.

日本語の概要は準備中です。原文の説明を表示しています。

oliver-kriska/claude-elixir-phoenix5652026年10月6日 更新

assigns

無料

Compatibility alias for the Elixir/Phoenix plugin's LiveView assigns audit. Invoke explicitly with /lv:assigns.

日本語の概要は準備中です。原文の説明を表示しています。

oliver-kriska/claude-elixir-phoenix5652026年10月6日 更新

Inspect LiveView socket assigns for memory bloat — missing temporary_assigns, unused assigns, unbounded lists needing streams, memory estimates. Use when LiveView memory grows or you need to add temporary_assigns.

日本語の概要は準備中です。原文の説明を表示しています。

oliver-kriska/claude-elixir-phoenix5652026年10月6日 更新

audit

無料

Project health audit and health check — architecture, performance, tests, dependencies, code quality. Use when assessing overall project health, before releases, or after refactors.

日本語の概要は準備中です。原文の説明を表示しています。

oliver-kriska/claude-elixir-phoenix5652026年10月6日 更新

Analyze Phoenix context boundaries and module coupling via mix xref. Use when checking cross-context calls, validating dependencies, before splitting modules, or reviewing architecture.

日本語の概要は準備中です。原文の説明を表示しています。

oliver-kriska/claude-elixir-phoenix5652026年10月6日 更新

oliver-kriska のスキルをすべて見る

このスキルの問題を報告する