testing-essentials
Testing Essentials
RULES — Follow these with no exceptions
- Follow the project's existing test setup patterns (e.g. shared setup helpers like
setup :store_test_session) — don't inline DataCase/ConnCase boilerplate that the project already abstracts away - Test both happy path AND error/invalid cases for every function
- Use
async: trueonly when safe — safe: pure functions, changesets, helpers; unsafe: DB contexts with shared rows, LiveView,Application.put_env, external services - Define test data in fixtures (
test/support/) — never build it inline across multiple tests - Use
has_element?/2andelement/2for LiveView assertions — nothtml =~ "text"for structure checks - Always test the unauthorized case for any protected resource
- Test the public context interface, not internal implementation details
- Use
describeblocks to group tests by function or behavior
TDD Workflow
Write the failing test first. Run it to confirm it fails for the right reason. Implement the minimum code to make it pass. Never write implementation before the test exists.
More from j-morgan6/elixir-phoenix-guide
oban-essentials
MANDATORY for ALL Oban work. Invoke before writing workers or enqueuing jobs.
1phoenix-json-api
MANDATORY for ALL JSON API work. Invoke before writing API controllers, pipelines, or JSON responses.
1ecto-essentials
MANDATORY for ALL database work. Invoke before modifying schemas, queries, or migrations.
1otp-essentials
MANDATORY for ALL OTP work. Invoke before writing GenServer, Supervisor, Task, or Agent modules.
1code-quality
Automated code quality detection — duplication, complexity, unused functions. Invoke when analyzing or refactoring Elixir code.
1phoenix-uploads
MANDATORY for file upload features. Invoke before implementing upload or file serving functionality.
1