Elixir Testing Rules

Enforce strict ExUnit testing rules for Elixir test quality.

24|4|Updated Nov 15, 2023
One-click install
npx skills add https://github.com/matthewsinclair/intent --skill elixir-testing-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Elixir Testing Rules
Source: https://github.com/matthewsinclair/intent/tree/main/intent/plugins/claude/skills/in-elixir-testing
Command: npx skills add https://github.com/matthewsinclair/intent --skill elixir-testing-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enforces best practices for writing Elixir tests, preventing common pitfalls like brittle tests, hidden failures, and over-reliance on mocks, leading to more reliable and maintainable codebases.

Core Features & Use Cases

  • Enforces Strong Assertions: Guides users to assert against concrete values, not just shapes.
  • Discourages Control Flow in Tests: Promotes clear, straight-line test execution.
  • Promotes Real Code Over Mocks: Encourages testing with actual implementations where possible.
  • Use Case: Ensure all your Elixir tests are focused, deterministic, and truly verify the behavior of your code, not just its structure.

Quick Start

Apply the Elixir testing rules to refactor the existing test suite.

Frequently Asked Questions about Elixir Testing Rules

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What are the best practices for writing ExUnit tests in Elixir?

ExUnit testing best practices involve avoiding control flow in test bodies, asserting against concrete values, focusing on one assertion per test, and testing the domain contract to ensure reliability and maintainability.

How do I avoid brittle Elixir tests that rely on mocks?

To avoid brittle Elixir tests, prefer using real code implementations over mocks. This approach ensures your tests verify actual behavior and domain contracts rather than just structural shapes or mock interactions.

Should I use multiple assertions in a single ExUnit test?

You should adhere to the Highlander Rule for ExUnit tests by focusing on one assertion per test. This practice prevents hidden failures and ensures your tests remain clear, deterministic, and easy to maintain.

How do I generate test data for Elixir ExUnit suites?

When generating test data for ExUnit suites, you should use globally unique values. This strict rule prevents state leakage between tests and ensures your Elixir test suite remains deterministic and isolated.

Can I use control flow statements inside Elixir test bodies?

You should avoid control flow in Elixir test bodies to promote clear, straight-line test execution. Removing conditional logic from tests prevents hidden failures and makes test logic easier to follow and maintain.

How do I align Elixir tests with existing specifications?

To align Elixir tests with specifications, ensure your tests verify the domain contract defined by any existing specs. This guarantees your tests accurately enforce the intended behavior and constraints of the codebase.