GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - maxohq/quick_factory

BranchesTags
Open more actions menu

Latest commit

 

History

25 Commits
25 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
lib
lib
 
 
test
test
 
 
.formatter.exs
.formatter.exs
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
README.md
README.md
 
 
mix.exs
mix.exs
 
 
mix.lock
mix.lock
 
 

Repository files navigation

QuickFactory

A lightweight, flexible factory library for Elixir that makes test data generation simple and intuitive.

Features

  • 🚀 Simple Setup - Define factories with minimal boilerplate
  • 🔧 Flexible Data Generation - Build structs, params, or insert directly to database
  • ✅ Changeset Validation - Optional validation using your schema's changesets
  • 🔄 Batch Operations - Generate multiple records at once
  • 🎯 Key Transformation - Support for atom, string, and camelCase keys
  • 📊 Built-in Counters - Generate unique values across test runs

Quick Start

1. Define a Factory

defmodule MyApp.UserFactory do
  use QuickFactory,
    schema: MyApp.User,
    repo: MyApp.Repo,
    changeset: :changeset

  def call(params \\ %{}) do
    %{
      name: "John Doe",
      email: "[email protected]",
      age: 25,
      first_name: "John",
      last_name: "Doe"
    }
    |> Map.merge(params)
  end
end

2. Generate Test Data

# Build a struct
user = UserFactory.build()
#=> %User{name: "John Doe", email: "[email protected]", age: 25}

# Build with custom params
user = UserFactory.build(%{name: "Jane"})
#=> %User{name: "Jane", email: "[email protected]", age: 25}

# Generate params only (great for API testing)
params = UserFactory.build_params(%{age: 30})
#=> %{name: "John Doe", email: "[email protected]", age: 30}

# Insert to database
user = UserFactory.insert!()

# Generate multiple records
users = UserFactory.insert_many!(3)

3. Key Transformations

Perfect for API testing with different key formats:

# Default: atom keys
UserFactory.build_params()
#=> %{name: "John Doe", first_name: "John", last_name: "Doe"}

# String keys
UserFactory.build_params(%{}, keys: :string)
#=> %{"name" => "John Doe", "first_name" => "John", "last_name" => "Doe"}

# CamelCase string keys (great for JSON APIs)
UserFactory.build_params(%{}, keys: :camel_string)
#=> %{"name" => "John Doe", "firstName" => "John", "lastName" => "Doe"}

Installation

Add quick_factory to your list of dependencies in mix.exs:

def deps do
  [
    {:quick_factory, "~> 0.2.0", only: :test}
  ]
end

Why QuickFactory?

  • Less Magic, More Control - Explicit factory definitions that are easy to understand
  • Test-Focused - Built specifically for testing scenarios
  • Ecto Integration - Works seamlessly with Ecto schemas and changesets
  • Lightweight - Minimal dependencies and overhead

Documentation

For full documentation, visit HexDocs.

Credits

Ideas / Code taken from:

  • https://github.com/theblitzapp/factory_ex with simplifications and removals.
  • https://github.com/beam-community/ex_machina/blob/main/lib/ex_machina/sequence.ex - nice sequence handling

About

No description, website, or topics provided.

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.