ex_machina
ExMachina is a test data factory library for Elixir that simplifies creation of realistic test records and their associations. It works seamlessly with Ecto but is flexible enough to work with any persistence layer.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | beam-community/ex_machina |
| Owner | beam-community |
| Primary language | Elixir |
| License | MIT — OSI-approved |
| Stars | 2.1k |
| Forks | 143 |
| Open issues | 3 |
| Latest release | v2.8.0 (2024-06-25) |
| Last updated | 2026-07-07 |
| Source | https://github.com/beam-community/ex_machina |
What ex_machina is
ExMachina provides a declarative DSL for defining factories that generate test data with support for sequences, lazy evaluation, nested associations, and both map/struct and non-map factories. It includes ExMachina.Ecto for direct database insertion and standalone mode for pure data generation.
Get the ex_machina source
Clone the repository and explore it locally.
git clone https://github.com/beam-community/ex_machina.gitcd ex_machina# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Factories must be defined in test/support (non-Phoenix) or lib (if compiled in test env); requires elixirc_paths configuration in mix.exs for non-Phoenix projects.
- Application.ensure_all_started(:ex_machina) must be called in test_helper.exs before ExUnit.start to enable factory compilation.
- Sequences are module-level state; care needed in parallel test suites to avoid collisions; consider using sequence(:name, &fn/1) with consistent logic.
- Lazy attribute evaluation via anonymous functions delays execution; useful for fresh instances per record but adds complexity if overused.
- Default factory behavior merges attributes automatically; custom factories with arity/1 require manual merge_attributes/2 and evaluate_lazy_attributes/1.
When to avoid it — and what to weigh
- Non-Elixir/non-Ecto projects — Language-specific to Elixir. Not applicable to Python, Node.js, Ruby, or other ecosystems (use FactoryBot, factory-boy, etc. instead).
- Real production data generation — ExMachina is test-only; it is not designed for seeding production databases or generating production fixtures.
- Non-struct/non-map data models — While non-map factories exist, Ecto integration requires Ecto schemas. Custom persistence requires significant manual configuration.
- Minimal test overhead projects — Small scripts or projects with no associations or complex data may see dependency overhead; inline test data may be simpler.
License & commercial use
MIT License. Permissive open-source license permitting commercial use, modification, and distribution with attribution and liability disclaimer.
MIT is a permissive OSI-approved license. Commercial use in private applications is permitted. Redistribution or bundling requires license file inclusion and attribution. Verify with legal if redistribution or SaaS license terms are material to your use case.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
ExMachina is test-only and not exposed to production. No direct security risk. Ensure factories do not hardcode sensitive test credentials or expose production data patterns; use sequences or Faker library for realistic but safe dummy values.
Alternatives to consider
Ecto.Factory or custom fixtures
Lower-level; requires manual association setup and sequence management. Simpler for minimal factories but scales poorly.
Faker (Elixir library)
Generates random fake data (names, emails, etc.) but does not create persistent records or manage associations. Often used alongside ExMachina.
Manual map/struct creation in tests
Direct control and no dependencies but leads to repeated boilerplate, brittle tests, and tight coupling to schema changes.
Build on ex_machina with DEV.co software developers
ExMachina eliminates boilerplate in test fixtures. Explore the docs, review the README examples, and evaluate integration with your Ecto or custom repository.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
ex_machina FAQ
Can ExMachina be used without Ecto?
How do I avoid creating the same associated record multiple times in one test?
Do I need to configure ExMachina in my Phoenix app?
Can I use ExMachina in non-test environments?
Software developers & web developers for hire
DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If ex_machina is part of your open-source testing roadmap, our team can implement, customize, migrate, and maintain it.
Ready to streamline your Elixir test data?
ExMachina eliminates boilerplate in test fixtures. Explore the docs, review the README examples, and evaluate integration with your Ecto or custom repository.