Fixture — Test Data Fixture Generator
A CLI tool for generating, managing, and exporting test data fixtures. Create reproducible datasets from templates with seeded randomness for consistent test environments.
Prerequisites
- - Python 3.8+
- INLINECODE0 shell
- Write access to INLINECODE1
Data Storage
All fixtures are stored in JSONL format at ~/.fixture/data.jsonl. Templates are stored at ~/.fixture/templates.json.
Commands
Run commands via: INLINECODE4
create
Create a new fixture record with specified fields and values.
CODEBLOCK0
Arguments:
- -
--name — Fixture name/label (required) - INLINECODE6 — Fixture type/category (required)
- INLINECODE7 — JSON object of field values (required)
load
Load fixtures from a JSON or JSONL file into the fixture store.
CODEBLOCK1
Arguments:
- -
--file — Input file path (required) - INLINECODE9 — File format:
json, jsonl (optional, default: auto-detect)
dump
Dump all fixtures or filtered subset to stdout or a file.
CODEBLOCK2
Arguments:
- -
--type — Filter by fixture type (optional) - INLINECODE13 — Output file path (optional, default: stdout)
list
List all fixtures with summary information.
CODEBLOCK3
Arguments:
- -
--type — Filter by fixture type (optional)
seed
Generate multiple fixture records from a template with seeded random data.
CODEBLOCK4
Arguments:
- -
--template — Template name to use (required) - INLINECODE16 — Number of records to generate (required)
- INLINECODE17 — Random seed for reproducibility (optional)
reset
Clear all fixtures or a specific type from the data store.
CODEBLOCK5
Arguments:
- -
--type — Only reset fixtures of this type (optional) - INLINECODE19 — Skip confirmation prompt (optional)
template
Manage fixture templates: create, list, or show template definitions.
CODEBLOCK6
Arguments:
- -
--list — List all templates (optional) - INLINECODE21 — Create template with given name (optional)
- INLINECODE22 — JSON schema for template creation (optional)
- INLINECODE23 — Show a specific template (optional)
validate
Validate fixtures against their template schema.
CODEBLOCK7
Arguments:
- -
--type — Validate only a specific type (optional)
export
Export fixtures to various formats: JSON, JSONL, CSV, SQL.
CODEBLOCK8
Arguments:
- -
--output — Output file path (required) - INLINECODE26 — Export format:
json, jsonl, csv, sql (required) - INLINECODE31 — Table name for SQL export (optional)
import
Import fixtures from external sources or standard formats.
CODEBLOCK9
Arguments:
- -
--file — Input file path (required) - INLINECODE33 — Assign fixture type (required)
help
Display help information and list all available commands.
CODEBLOCK10
version
Display the current tool version.
CODEBLOCK11
Examples
CODEBLOCK12
Notes
- - Templates define field types:
string, email, int:min-max, float:min-max, bool, uuid, INLINECODE40 - Seeded generation guarantees identical output given the same seed
- Use
validate to check fixtures match their template schema - SQL export generates INSERT statements compatible with most databases
Powered by BytesAgain | bytesagain.com | hello@bytesagain.com
Fixture — 测试数据固定装置生成器
一个用于生成、管理和导出测试数据固定装置的CLI工具。通过带种子的随机性从模板创建可复现的数据集,确保一致的测试环境。
前置条件
- - Python 3.8+
- bash shell
- 对 ~/.fixture/ 的写入权限
数据存储
所有固定装置以JSONL格式存储在 ~/.fixture/data.jsonl。模板存储在 ~/.fixture/templates.json。
命令
通过以下方式运行命令:bash scripts/script.sh [arguments...]
create
创建具有指定字段和值的新固定装置记录。
bash
bash scripts/script.sh create --name test_user --type user --fields {name:Alice,email:alice@test.com,age:30}
参数:
- - --name — 固定装置名称/标签(必需)
- --type — 固定装置类型/类别(必需)
- --fields — 字段值的JSON对象(必需)
load
从JSON或JSONL文件加载固定装置到固定装置存储中。
bash
bash scripts/script.sh load --file fixtures.json
bash scripts/script.sh load --file data.jsonl --format jsonl
参数:
- - --file — 输入文件路径(必需)
- --format — 文件格式:json、jsonl(可选,默认:自动检测)
dump
将所有固定装置或过滤后的子集输出到标准输出或文件。
bash
bash scripts/script.sh dump
bash scripts/script.sh dump --type user --output users.json
参数:
- - --type — 按固定装置类型过滤(可选)
- --output — 输出文件路径(可选,默认:标准输出)
list
列出所有固定装置及其摘要信息。
bash
bash scripts/script.sh list
bash scripts/script.sh list --type user
参数:
seed
从模板生成多个带有种子随机数据的固定装置记录。
bash
bash scripts/script.sh seed --template user --count 10 --seed 42
参数:
- - --template — 要使用的模板名称(必需)
- --count — 要生成的记录数量(必需)
- --seed — 用于可复现性的随机种子(可选)
reset
从数据存储中清除所有固定装置或特定类型的固定装置。
bash
bash scripts/script.sh reset
bash scripts/script.sh reset --type user
参数:
- - --type — 仅重置此类型的固定装置(可选)
- --confirm — 跳过确认提示(可选)
template
管理固定装置模板:创建、列出或显示模板定义。
bash
bash scripts/script.sh template --list
bash scripts/script.sh template --create user --schema {name:string,email:email,age:int:18-65}
bash scripts/script.sh template --show user
参数:
- - --list — 列出所有模板(可选)
- --create — 使用给定名称创建模板(可选)
- --schema — 用于模板创建的JSON模式(可选)
- --show — 显示特定模板(可选)
validate
根据模板模式验证固定装置。
bash
bash scripts/script.sh validate
bash scripts/script.sh validate --type user
参数:
export
将固定装置导出为各种格式:JSON、JSONL、CSV、SQL。
bash
bash scripts/script.sh export --output fixtures.csv --format csv
bash scripts/script.sh export --output seed.sql --format sql --table users
参数:
- - --output — 输出文件路径(必需)
- --format — 导出格式:json、jsonl、csv、sql(必需)
- --table — SQL导出的表名(可选)
import
从外部源或标准格式导入固定装置。
bash
bash scripts/script.sh import --file data.csv --type user
参数:
- - --file — 输入文件路径(必需)
- --type — 分配固定装置类型(必需)
help
显示帮助信息并列出所有可用命令。
bash
bash scripts/script.sh help
version
显示当前工具版本。
bash
bash scripts/script.sh version
示例
bash
创建模板
bash scripts/script.sh template --create user --schema {name:string,email:email,age:int:18-65}
生成50个用户
bash scripts/script.sh seed --template user --count 50 --seed 42
列出所有固定装置
bash scripts/script.sh list
导出为SQL
bash scripts/script.sh export --output seed.sql --format sql --table users
重置所有数据
bash scripts/script.sh reset --confirm
说明
- - 模板定义字段类型:string、email、int:min-max、float:min-max、bool、uuid、date
- 使用相同种子进行生成可保证输出完全相同
- 使用 validate 检查固定装置是否匹配其模板模式
- SQL导出生成兼容大多数数据库的INSERT语句
由BytesAgain提供 | bytesagain.com | hello@bytesagain.com