testing-essentials
Installation
SKILL.md
Testing Essentials
RULES — Follow these with no exceptions
- Use
DataCasefor database tests,ConnCasefor LiveView/controller tests — never mix them - 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.