---
title: "Test against the same database engine · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/integration-and-contract-tests/same-database-engine
updated: 2026-10-20
licence: "All rights reserved"
---

# Test against the same database engine

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Integration and contract tests](https://agentwranglers.se/playbook/testing/integration-and-contract-tests)
- Rule: Test database code against the same database engine and version as production, never against a different engine or a mock.
- How: Start the database in a container for the test run, for example with Testcontainers or a Compose file. Run the migrations before the tests. An in-memory stand-in such as SQLite for a PostgreSQL app hides bugs in queries, types and locking. Unit tests of logic that takes plain data need no database at all.
- Check: The test setup starts the production database engine at the same major version as production and runs every migration. A query that only works on the stand-in fails the suite.

Example:

```js
import { PostgreSqlContainer } from '@testcontainers/postgresql';

const db = await new PostgreSqlContainer('postgres:18').start();
process.env.DATABASE_URL = db.getConnectionUri();
await runMigrations();
```

```python
# Python with testcontainers
from testcontainers.postgres import PostgresContainer

with PostgresContainer("postgres:18", driver=None) as database:
    os.environ["DATABASE_URL"] = database.get_connection_url()
    run_migrations()
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/integration-and-contract-tests/same-database-engine`.

- Next: [Fake only what you do not own](https://agentwranglers.se/playbook/testing/integration-and-contract-tests/doubles-at-the-edge)
- [Integration and contract tests](https://agentwranglers.se/playbook/testing/integration-and-contract-tests)
