Fixgen - Language agnostic fixture generator
Usually wiring up fake test data is a bunch of work, especially when that data is relational. Fixgen helps to alleviate some of that pain by allowing you to very easily generate fixtures that can also reference other fixtures. It also has some nice characteristics:
- Single binary without dependencies
- Language agnostic
- Simple syntax
- Supports relations
- Written in OCaml
Note: This does not replace fuzz testing. The generated data will try to be realistic, rather than testing edge cases.
Install
Check out the latest release binary, which contains install instructions.
Usage
Fixgen makes it simple to generate fixtures. It comes with a tiny DSL:
$ fixgen 'user (2): id uuidv4, name name; purchase (10): id uuidv4, buyer user.id, amount int(1,40), currency ("USD","MXN")' -o fixtures
This will generate two files:
- fixtures/user.csv, will have two rows containing id and name
- fixtures/purchase.csv, will have ten rows containing id, buyer (which will reference ids from user!), amount, currency.
You can then import it into your SQL server with simple copy from commands
COPY users FROM '/fixtures/user.csv' CSV HEADER;
COPY purchases FROM '/fixtures/purchase.csv' CSV HEADER;
Or maybe export as JSON instead to import into your NoSQL DB.
$ fixgen 'user (2): id uuidv4, name name; purchase (3): id uuidv4, buyer user.id, amount int(1,40), currency: ("USD","MXN")' -f json
This will print two JSON arrays to stdout.
Supported types
Fixgen comes with the following built-in types:
- name
$ fixgen 'user (1): id name'
id
John
- uuidv4
$ fixgen '_(1): id uuiv4'
id
6ebe54f5-24b3-43ae-a9e4-f91c481755e
- int(min,max)
$ fixgen '_(2): number int(2,40)'
number
2
37
- constants
$ fixgen '_(2): name "Bob"'
name
Bob
Bob
- Union
$ fixgen '_(4): currency ("SEK","MXN","USD")'
currency
SEK
USD
MXN
MXN
$ fixgen '_(1): email email'
email
judy@gmail.com
- increment
$ fixgen '_(4): id increment'
id
1
2
3
4
- Username
$ fixgen '_(4): user username'
user
ivan0
judy1
frank2
walter3
- Dates (Future, Present, Past)
$ fixgen '_(2): created_at past'
created_at
2001-07-19T18:35:13+00:00
2011-06-21T04:31:47+00:00
Development - Prerequisites
After installation, you will need to run direnv allow
direnv allow
And it will set up the development environment for you with the correct git hooks.
VSCode
You'll need OCaml platform and direnv extension. Once you have those, you will need to start the project from the terminal. First, ensure you have setup code terminal command:
https://code.visualstudio.com/docs/setup/mac
Once in place, cd to the project and run
code .
And VSCode should launch correctly with LSP installed.
Running development
./scripts/run-watch.sh
Run tests
./scripts/run-test-watch.sh
You can also run them manually:
dune runtests
Building
dune build
Contributing
Send your patches via mail. New to mailing patches? Check out this tutorial.