An Elixir mocking library that patches functions for testing with unique superpowers like patching private functions.
Patch is an ergonomic mocking library for Elixir that integrates with ExUnit to simplify testing by replacing functionality with test-specific behavior. It provides a straightforward approach where patched functions always return their mock values, eliminating common testing complexities and ensuring predictable test environments.
Elixir developers writing unit and integration tests who need to mock dependencies, especially those working with GenServers, processes, or testing private functions without altering visibility.
Developers choose Patch over alternatives like meck, Mock, or Mox for its unique 'Super Powers': it patches both local and remote calls consistently, can patch and expose private functions without changing their visibility, and keeps testing logic completely separate from production code.
Ergonomic Mocking for Elixir
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Offers an easy-to-use interface with sensible defaults, as highlighted in the README's features, making it straightforward to integrate with ExUnit tests.
Provides first-class utilities for mocking Elixir Processes and GenServers, including intercepting messages and injecting listeners, which simplifies testing concurrent code.
Keeps testing logic completely separate from application code without requiring modifications, ensuring clean separation of concerns as emphasized in the philosophy.
Enables patching of private functions without changing visibility and ensures mocks work for both local and remote calls, offering capabilities not found in other Elixir mocking libraries.
Supports complex mock behaviors with scalars, callables, sequences, cycles, and exceptions, allowing for dynamic and realistic test scenarios as detailed in the value builders section.
Explicitly incompatible with async: true due to global module recompilation, which can hinder test performance and parallel execution in larger suites.
Alters the global execution environment by recompiling modules, potentially causing test pollution or unintended interactions between tests if not carefully managed.
As a newer library with unique approaches, it may have fewer third-party integrations or community resources compared to established alternatives like Mox or meck.