Three-and-a-half Ways of Testing your Repositories
Are your repository tests brittle and slow? Discover how to use ephemeral containers for high-fidelity tests that are fast, reliable, and nearly identical to production.
#1about 5 minutes
Introduction to repositories in domain-driven design
Repositories act as an abstraction layer between the domain and infrastructure, separating business logic from data persistence concerns.
#2about 9 minutes
Mocking the client API for fast and isolated tests
The first method involves replacing the backend client, like an S3 client, with a mock object to verify that the correct methods are called.
#3about 8 minutes
Mocking the backend service for client-agnostic tests
Instead of mocking the client library, you can intercept and mock the HTTP requests it makes to the backend service, like DynamoDB.
#4about 3 minutes
The brittleness of mocking SQL statements directly
Asserting on exact SQL strings is a fragile approach because minor refactoring, like adding parameters, will break the tests.
#5about 6 minutes
Testing against a real, persistent database service
Using a shared development or staging database provides a realistic environment but introduces significant challenges with state management and cleanup.
#6about 7 minutes
Using temporary services with Testcontainers for reliable tests
Testcontainers allows you to programmatically spin up ephemeral database instances in Docker, enabling realistic and isolated roundtrip testing.
#7about 4 minutes
Comparing the pros and cons of each testing method
A final summary compares the speed, complexity, and implementation coupling of client mocking, service mocking, and testing against real or temporary services.
#8about 15 minutes
Q&A on testing strategies and CI/CD integration
The Q&A covers choosing mocking frameworks, balancing unit and integration tests, handling data migrations, and integrating repository tests into CI/CD pipelines.
Related jobs
Jobs that call for the skills explored in this talk.
Dev Digest 216: CyberSec + Mythos, Stack Overflow for Agents & DOOM in TTFInside last week’s Dev Digest 216 .
🧠 Prompts are now tools in Chrome
📜 The AI Coding Agent Manifesto
🔐 How Claude Mythos changes Cyber Security
🧱 GitHub Stacked PRs to battle AI slop
⚙️ Git commands to run before reading code
🐍 A Python framework f...
Daniel Cranney
Dev Digest 197: Dunning–Kruger Steroids, State of Cloud Security, Puppies > BeerInside last week’s Dev Digest 197 .
💪 LLMs are steroids for Dunning-Kruger
☁️ The state of cloud security
🟨 JavaScript for Django developers
🔀 Redirects hurt your page rank
🤔 Is your node setup vulnerable?
💿 Meta data on audio CDs
🐶 OSS: More puppie...
5 GitHub Repos That Help You Ship and Show Your WorkIf you’re a regular reader here, you’ll know we absolutely love open source.
In particular, we have a soft spot for the small, practical repos, the ones that don’t look like much at first glance, but turn out to be incredibly useful.
We’ve rounded up...
From learning to earning
Jobs that call for the skills explored in this talk.