A flexible library for creating test data and associations in Elixir applications, with seamless Ecto integration.
ExMachina is an Elixir library designed to create test data and associations efficiently for Elixir applications. It solves the problem of setting up complex, realistic test fixtures by providing a factory pattern with seamless Ecto integration and support for sequences, derived attributes, and lazy evaluation.
Elixir developers building applications with Ecto or other persistence layers who need to generate consistent, maintainable test data for unit and integration tests.
Developers choose ExMachina for its clean syntax, automatic association handling, and flexibility—it works out-of-the-box with Ecto but can be adapted for any persistence library, and it supports custom strategies for extended use cases.
Create test data for Elixir applications
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a clean, readable way to define factories with sequences and lazy evaluation, reducing boilerplate in test setup as shown in the README examples.
With Ecto integration, it automatically persists associations when using `insert` functions, streamlining complex test data creation without manual database calls.
Includes `params_for` and `string_params_for` to easily generate maps for controller testing, aligning seamlessly with Phoenix workflows.
Supports custom strategies like JSON encoding, allowing adaptation beyond Ecto for various testing scenarios, as documented in the README.
Core features like `insert` and `params_for` are only available with Ecto, making it less useful for non-database projects and limiting flexibility.
Setup requires adjusting `elixirc_paths` and application startup, especially for non-Phoenix projects, which can be error-prone and time-consuming.
Concepts like delayed evaluation and custom strategies require a deep understanding of Elixir's evaluation model, potentially confusing developers new to the library.
ex_machina is an open-source alternative to the following products: