ExMachina makes it easy to generate Elixir test data using factories. It works out of the box with Ecto associations and embeds, and can be easily composed to make creating data extremely flexible. defmodule MyApp.Factory do use ExMachina.Ecto, repo: MyApp.Repo def factory(:user, _attrs) do %User{ name: "Jane Smith", email: sequence(:email, fn(n) -> "email-#{n}@example.com" end) } end def factory(:article, attrs) do %Article{ title: "Use ExMachina!", # Use the :author from the attrs if it exists, otherwise build a new :user author: assoc(attrs, :author, factory: :user) } end end ExMachina is simple enough to use like this… user = create(:user, name: "Kanye West") articles = create_pair(:article, author: user) …but flexible enough to use like this: def make_admin(user) do %{user | admin: true} end build(:user) |> make_admin |> create Flexibility is a feature ExMachina striv...