Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Create test data for Elixir applications
| Date | Stars |
|---|---|
| 2026-07-30 | 2056 |
| 2026-08-06 | 2056 |
| 2026-08-07 | 2055 |
| 2026-08-19 | 2056 |
| 2026-08-20 | 2057 |
| 2026-08-24 | 2058 |
| 2026-08-28 | 2057 |
| 2026-09-13 | 2058 |
| 2026-09-23 | 2059 |
| 2026-09-29 | 2060 |
| 2026-10-06 | 2061 |
| 2026-10-22 | 2062 |
| 2026-10-26 | 2063 |
| 2026-11-01 | 2065 |
| 2026-11-04 | 2065 |
Today
— stars today
This week
+2 stars this week
This month
+5 stars this month
Momentum
7.0
growth rate 0.10%/day
# ExMachina
[](https://github.com/beam-community/ex_machina/actions/workflows/ci.yaml)
[](https://hex.pm/packages/ex_machina)
[](https://hexdocs.pm/ex_machina/)
[](https://hex.pm/packages/ex_machina)
[](https://github.com/beam-community/ex_machina/blob/master/LICENSE)
[](https://github.com/beam-community/ex_machina/commits/master)
ExMachina makes it easy to create test data and associations. It works great
with Ecto, but is configurable to work with any persistence library.
> **This README follows the main branch, which may not be the currently published version**. Here are the
[docs for the latest published version of ExMachina](https://hexdocs.pm/ex_machina/readme.html).
## Installation
In `mix.exs`, add the ExMachina dependency:
<!-- {x-release-please-start-version} -->
```elixir
def deps do
[
{:ex_machina, "~> 2.8.2", only: :test},
]
end
```
<!-- {x-release-please-end} -->
Add your factory module inside `test/support` so that it is only compiled in the
test environment.
Next, be sure to start the application in your `test/test_helper.exs` before
ExUnit.start:
```elixir
{:ok, _} = Application.ensure_all_started(:ex_machina)
```
#### Install in just the test environment for non-Phoenix projects
You will follow the same instructions as above, but you will also need to add
`test/support` to your compilation paths (elixirc_paths) if you have not done
so already.
In `mix.exs`, add test/support to your elixirc_paths for just the test env.
```elixir
def project do
[app: ...,
# Add this if it's not already in your project definition.
elixirc_paths: elixirc_paths(Mix.env)]
end
# This makes sure your factory and any other modules in test/support are compiled
# when in the test environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
```
## Overview
[Check out the docs](https://hexdocs.pm/ex_machina/ExMachina.html) for more details.
Define factories:
```elixir
defmodule MyApp.Factory do
# with Ecto
use ExMachina.Ecto, repo: MyApp.Repo
# without Ecto
use ExMachina
def user_factory do
%MyApp.User{
name: "Jane Smith",
email: sequence(:email, &"email-#{&1}@example.com"),
role: sequence(:role, ["admin", "user", "other"]),
}
end
def article_factory do
title = sequence(:title, &"Use ExMachina! (Part #{&1})")
# derived attribute
slug = MyApp.Article.title_to_slug(title)
%MyApp.Article{
title: title,
slug: slug,
# another way to build derived attributes
tags: fn article ->
if String.contains?(article.title, "Silly") do
["silly"]
else
[]
end
end,
# associations are inserted when you call `insert`
author: build(:user)
}
end
# derived factory
def featured_article_factory do
struct!(
article_factory(),
%{
featured: true,
}
)
end
def comment_factory do
%MyApp.Comment{
text: "It's great!",
article: build(:article),
}
end
end
```
Using factories ([check out the docs](https://hexdocs.pm/ex_machina/ExMachina.html) for more details):
```elixir
# `attrs` are automatically merged in for all build/insert functions.
# `build*` returns an unsaved comment.
# Associated records defined on the factory are built.
attrs = %{body: "A comment!"} # attrs is optional. Also accepts a keyword list.
build(:comment, attrs)
build_pair(:comment, attrs)
build_list(3, :comment, attrs)
# `insert*` returns an inserted comment. Only works with EExcerpt of 14,271 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:99e98773cc12b67f, topic:testing