test-mocking

Mock Elixir dependencies using compile-time injection and Mox.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/ityonemo/pepper --skill test-mocking-ityonemo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-mocking
Source: https://github.com/ityonemo/pepper/tree/main/.claude/skills/test-mocking
Command: npx skills add https://github.com/ityonemo/pepper --skill test-mocking-ityonemo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill simplifies the process of isolating components for testing by providing clear guidelines and strategies for mocking dependencies, ensuring robust and reliable unit tests.

Core Features & Use Cases

  • Compile-time Injection: Ensures dependencies are resolved at compile time for performance and predictability.
  • Mox Integration: Leverages Mox for mocking protocol implementations, a common pattern in Elixir.
  • Ad-hoc Mocks: Facilitates quick creation of mocks for external or single-use modules without formal behavior definitions.
  • Stub vs. Expect: Differentiates between stubbing for multi-call scenarios and expecting for specific call verification.
  • Use Case: When testing a module that relies on an external API client, you can use this Skill's techniques to mock the API client, allowing you to test your module's logic in isolation without making actual network requests.

Quick Start

Configure your test environment to use a mock implementation for the Pepper.Image module.

Frequently Asked Questions about test-mocking

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

FAQPage Schema
How do I mock dependencies in Elixir tests?

Mock dependencies in Elixir tests by configuring compile-time injection for predictable resolution and applying the Mox library to define mock behaviors for external modules and protocol implementations.

What is the difference between stub and expect in Mox?

The difference between stub and expect in Mox is that stubbing provides default implementations for multi-call scenarios, while expecting defines specific call verifications to ensure a mock is invoked during the test.

How does compile-time injection work for Elixir testing?

Compile-time injection for Elixir testing works by resolving dependencies at compile time rather than runtime, ensuring predictable test execution and improving performance by replacing external modules with mock implementations.

Can I mock external API clients in Elixir without making network requests?

Yes, you can mock external API clients in Elixir without network requests by creating ad-hoc mocks for single-use modules or using Mox to define behaviors, isolating your module logic for reliable unit testing.

When should I use ad-hoc mocks versus formal behavior definitions in Elixir?

Use ad-hoc mocks in Elixir for quick mocking of external or single-use modules without formal behavior definitions, whereas formal behaviors with Mox are needed for mocking protocol implementations and verifying specific calls.