Set Up Test Databases

Configure a separate database for running tests without affecting development data.

Prerequisites

  • CQL installed

  • Database server running

  • Test framework configured

Create Test Database

PostgreSQL

createdb myapp_test

MySQL

mysql -e "CREATE DATABASE myapp_test"

SQLite

SQLite creates the file automatically; use a separate path.

Configure Test Environment

Create a test configuration:

Environment Variables

Set test database URL:

Or in your test helper:

Run Migrations for Tests

Before running tests, migrate the test database:

Or with a script:

Database Cleaning Strategies

Fast cleanup by truncating tables:

Transaction Rollback

Wrap each test in a transaction that rolls back:

Note: This won't work if your tests use multiple connections or spawn fibers.

Delete Strategy

Slower but compatible with all scenarios:

In-Memory SQLite

For fastest tests, use in-memory SQLite:

Separate Test Schema

Use a dedicated schema module for tests:

Parallel Tests

For parallel test execution, use separate databases:

Verify Setup

See Also

Last updated

Was this helpful?