How to convert json to sql test fixture insert statements
- Step 1Define the fixture as a JSON array — Write the fixture records as a JSON array of objects. Use deterministic IDs (e.g. 1, 2, 3) so test assertions can reference specific records by ID without querying the database.
- Step 2Set the target table and include TRUNCATE — Enter the table name and enable the 'Add TRUNCATE TABLE before INSERT' option. This ensures each test run starts from a clean known state rather than accumulating rows from prior runs.
- Step 3Generate and save the fixture SQL — Download the SQL file and place it in your test support directory — e.g. tests/fixtures/users.sql or __tests__/db/seed.sql.
- Step 4Load in your test setup hook — In Jest's globalSetup or beforeAll: read the SQL file with fs.readFileSync and execute it via your database client. For PHPUnit, reference the file in getDataSet(). For pytest-django, use django.test.TestCase.fixtures or a conftest.py fixture.
Frequently asked questions
Should I commit fixture SQL files to version control?+
Yes. Fixture SQL files are source of truth for test data and should be committed alongside your test code. When the schema changes, update both the fixture SQL and any affected test assertions in the same pull request so the change is reviewable together.
How do I handle foreign keys between fixture tables?+
Generate fixture SQL for parent tables first (users, categories) and child tables second (posts, products). Load them in that order in your setup hook. If your database enforces foreign keys, use SET FOREIGN_KEY_CHECKS=0 (MySQL) or DEFERRABLE INITIALLY DEFERRED (PostgreSQL) during the load to avoid ordering issues.
Is the test fixture data — including synthetic user records — transmitted to JAD Apps?+
No. SQL generation runs entirely in your browser. Fixture records, internal IDs, and any test-specific data values are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.