
Testcontainers
Spins up real databases, message queues, and other infrastructure in Docker containers for your integration tests instead of mocking them out. You get actual SQL Server, PostgreSQL, RabbitMQ, or whatever you need running in isolation with random ports and automatic cleanup. The big win is catching real issues like constraint violations, SQL syntax errors, and migration problems that mocks would happily let through. Works with xunit's IAsyncLifetime pattern and handles the container lifecycle so you're not manually managing Docker in your CI pipeline. If you've ever had a mock-heavy test suite pass locally only to explode in production because the real database behaves differently, this is worth the extra few seconds of container startup time.
- skills.sh installs
- 569
- GitHub stars
- 90
- last updated
- Aug 21, 2026
Install
$ npx -y skills add wshaddix/dotnet-skills --skill testcontainers --agent claude-codeInstalls into .claude/skills of the current project.
Files
Integration Testing with TestContainers
When to Use This Skill
Use this skill when:
- Writing integration tests that need real infrastructure (databases, caches, message queues)
- Testing data access layers against actual databases
- Verifying message queue integrations
- Testing Redis caching behavior
- Avoiding mocks for infrastructure components
- Ensuring tests work against production-like environments
- Testing database migrations and schema changes
Core Principles
- Real Infrastructure Over Mocks - Use actual databases/services in containers, not mocks
- Test Isolation - Each test gets fresh containers or fresh data
- Automatic Cleanup - TestContainers handles container lifecycle and cleanup
- Fast Startup - Reuse containers across tests in the same class when appropriate
- CI/CD Compatible - Works seamlessly in Docker-enabled CI environments
- Port Randomization - Containers use random ports to avoid conflicts
Why TestContainers Over Mocks?
Problems with Mocking Infrastructure
// BAD: Mocking a database
public class OrderRepositoryTests
{
private readonly Mock<IDbConnection> _mockDb = new();
Sponsors
Details
- Repository
- github.com/wshaddix/dotnet-skills
- Categories
- Testing & QA, DevOps & CI/CD, Documentation, .NET & C#
- First seen
- Jun 3, 2026
More from wshaddix/dotnet-skills
All 13- Microsoft Extensions Dependency Injection552
- Logging Observability545
- Validation Patterns542
- Project Structure539
- Dotnet Domain Modeling538
- Serialization530
- Microsoft Extensions Configuration528
- Package Management518
- Dotnet Testing Strategy619
- Dotnet Xunit619
- Modern Csharp Coding Standards589
- Csharp Wolverinefx572