Getting started
Five minutes from an installed tfg to a set of test files your tests can rely on. Every
command here runs as it is, on Windows, macOS and Linux. If you have not installed it yet, start
with Install.
-
Make one file of an exact size
Name the format, the size and the folder. This makes one PNG of exactly two megabytes:
tfg generate --format png --size 2mb --out ./out1 file in 1 target, 2 097 152 B totalSizes count in 1024s, the way a file manager does, so
2mbis 2 097 152 bytes. A plain byte count works too. The PNG opens in any picture viewer, and beside it ismanifest.json, the record of what the run made and how your system should react to each file. -
Make many files at once
Ten thousand log files, each between one and eight kilobytes. The sizes are drawn from the seed, so the same command gives the same set tomorrow and on any other machine:
tfg generate --format log --size-range 1kb-8kb --count 10000 --out ./logsGive each run its own folder. The manifest is the only record of what a run wrote, so a second run into a folder that holds one is refused rather than written over it. Add
--number-if-takento put the second run beside the first instead. -
Check the files, then remove them
verifysays whether every file is still there and still the same.cleanupremoves the files the manifest lists and nothing else. Without--yesit only says what it would remove:tfg verify ./out/manifest.json tfg cleanup ./out/manifest.json tfg cleanup ./out/manifest.json --yesout matches ./out/manifest.json: 1 file checked 1 file would be removed from out: remove files_0001.png Nothing was removed. Run the same command with --yes to remove them. 1 file removed from out -
Say what your system should do with the files
A test file is only half a test. The other half is what should happen to it. Write it on the command line and the manifest carries it beside every file:
tfg generate --format pdf --size 12mb --expected reject --expected-reason size_limit --out ./too-bigFor a size limit, the
size-boundariespreset makes the whole set at once: files just under the limit, at it and just over it, each with its expected outcome:tfg generate --preset size-boundaries --limit 10mb --format pdf --out ./limit -
Make a file that is broken on purpose
A damaged file still has the size you asked for, and the manifest expects your system to turn it away.
tfg damagelists the damages this build has:tfg generate --format png --size 2mb --damage zero-head --out ./broken -
Turn the run into a recipe
Once the set is right, write it down. A recipe is a short YAML file you commit beside your tests, so the files never have to be committed: anyone rebuilds them, byte for byte.
# fixtures.yaml version: 1 seed: 7741 targets: - id: invoices format: pdf count: 25 size: 300kb name: invoice_{index:04}.pdf expected: accept - id: too_big format: pdf size: 12mb expected: outcome: reject reason: size_limit output: dir: ./fixturestfg validate fixtures.yaml tfg generate fixtures.yamlvalidatechecks the recipe and writes nothing. Every key is in the recipe reference, and the recipe gallery has ready recipes to start from.
Where to go next
- Test files in CI - a GitHub Actions workflow and a GitLab job that build the set in the pipeline
- Test frameworks - the set inside pytest, Playwright, Vitest and
node:test - The manifest - every field a test can read
- Commands - every flag of every command
- Presets - ready sets for common testing questions