TE

Elixir Testing

Elixir testing conventions

Details

Language / Topic
elixirElixir
Category
Testing

Rules

balanced
- Use ExUnit with `describe` and `test` blocks. Run tests with `mix test`.
- Use `assert` and `refute` macros. Pattern match on results in assertions.
- Use `ExUnit.Case` with `setup` callbacks for test fixtures — use `Mox` for mocking and define behaviors for testable boundaries.
- Use `setup` blocks for shared test context. Return data as maps from setup for test access.
- Use `async: true` on test modules that don't share database state for parallel execution.
- Use `Mox` for mock-based testing: define behaviours, create mocks, set expectations.
- Use tags (`@tag :integration`) to categorize and selectively run test subsets.