# Data Access Testing With @testcontainers

DevFeed: [Data Access Testing With @testcontainers](<https://devfeed.tech/articles/data-access-testing-with-testcontainers-117746.md>)

Original publisher: [Read original article](<https://blog.master.dev/data-access-testing-with-testcontainers/>)

Author: Adam Rackis

Published: 2026-11-04T12:58:05Z

Content type: tutorial

Language: en

Sources: [Master.dev Blog RSS Feed](<https://devfeed.tech/sources/master-dev-blog-rss-feed.md>)

Topics: [Integration testing](<https://devfeed.tech/topics/integration-testing.md>), [Testcontainers](<https://devfeed.tech/topics/testcontainers.md>), [mutation-testing](<https://devfeed.tech/topics/mutation-testing.md>), [Unit testing](<https://devfeed.tech/topics/unit-testing.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [ai-agents](<https://devfeed.tech/tags/ai-agents.md>), [blog-post](<https://devfeed.tech/tags/blog-post.md>), [ci-cd](<https://devfeed.tech/tags/ci-cd.md>), [claude](<https://devfeed.tech/tags/claude.md>), [cli](<https://devfeed.tech/tags/cli.md>), [container](<https://devfeed.tech/tags/container.md>), [containers](<https://devfeed.tech/tags/containers.md>), [crud](<https://devfeed.tech/tags/crud.md>), [database](<https://devfeed.tech/tags/database.md>), [database-schema](<https://devfeed.tech/tags/database-schema.md>), [docker](<https://devfeed.tech/tags/docker.md>), [docker-container](<https://devfeed.tech/tags/docker-container.md>), [drizzle](<https://devfeed.tech/tags/drizzle.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [schema](<https://devfeed.tech/tags/schema.md>), [testcontainers](<https://devfeed.tech/tags/testcontainers.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

## AI overview

For complex data access logic, an isolated database integration test can verify that real inserts and queries preserve the expected object structure. The article uses `@testcontainers/postgresql` to start a temporary Postgres container in Vitest, applies a Drizzle schema with `drizzle-kit push`, and exercises workout insertion and retrieval through the application's actual code. A round-trip assertion catches errors in joins, writes, or ordering without tying the test to particular table rows, which the author says makes it less fragile to schema changes. The tradeoff is setup time: the suite takes over a second to start, and Docker must be available locally; GitHub Actions Ubuntu runners are said to include it. The author recommends reserving this approach for meaningful, non-trivial database logic rather than basic CRUD tests.

## Source excerpt

Testing data access code has always been awkward: unit tests want to be fast and isolated, and a real database is neither. With Docker and @testcontainers you can spin up a throwaway Postgres inside your Vitest suite, push your Drizzle schema into it, and verify that your real insert and query code round-trips correctly.