
Fixtures in JSON for Database Tests With PostgreSQL
Load JSON fixtures into PostgreSQL for tests with jsonb_populate_recordset: 25,000 rows in 0.21 s, bad fixtures caught by constraints, one typo missed.
Tag
9 posts

Load JSON fixtures into PostgreSQL for tests with jsonb_populate_recordset: 25,000 rows in 0.21 s, bad fixtures caught by constraints, one typo missed.

Test a JSON API against its OpenAPI contract with Schemathesis: 1,903 generated requests found a 500 and undocumented statuses, and missed one bug.

Generate JSON test data with Faker, Hypothesis, SQL and jq: seeds for repeatable runs, collisions, and a property test that found real bugs.

Compare JSON documents in tests while ignoring ids and timestamps: strip keys, DeepDiff exclusions, placeholders that keep relations, jq del, float tolerance.

Snapshot tests for JSON in pytest with syrupy and Node's test runner: what a snapshot stores, why random ids break it, and matchers and scrubbing that fix it.

Test a generated Excel report with pytest: structure, control totals, formulas, formats and edge cases, plus a fixture of bad input and a golden file.

A tested guide to testing JSON output: asserts, snapshots, volatile fields, schemas, generated data, fixtures and property tests, with a mutation matrix.

Test a YAML pipeline runner with pytest: order, unknown steps, cycles, duplicates, a Hypothesis property over random graphs and a check that the tests bite.

Keep test data in YAML files, load it inside a transaction per test and roll back after, with pytest and PostgreSQL. Three tests ran in 0.13 seconds.