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-code

Installs 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

  1. Real Infrastructure Over Mocks - Use actual databases/services in containers, not mocks
  2. Test Isolation - Each test gets fresh containers or fresh data
  3. Automatic Cleanup - TestContainers handles container lifecycle and cleanup
  4. Fast Startup - Reuse containers across tests in the same class when appropriate
  5. CI/CD Compatible - Works seamlessly in Docker-enabled CI environments
  6. 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
1everyinc avataragent-browsereveryinc/compound-engineering-pluginBrowser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking scr542skills.sh installs
2evoscientist avatarpaper-reviewevoscientist/evoskillsGuides self-review of YOUR OWN academic paper before submission with adversarial stress-testing. Core method: 5-aspect checklist (contribution sufficiency, writ521skills.sh installs
3tldraw avatarwrite-unit-teststldraw/tldrawWriting unit and integration tests for the tldraw SDK. Use when creating new tests, adding test coverage, or fixing failing tests in packages/editor or packages503skills.sh installs
4longbridge avatarlongbridge-risk-analysislongbridge/skillsRisk measurement and stress testing via Longbridge — computes VaR (historical simulation / parametric), CVaR (expected shortfall), max drawdown, Sharpe ratio, C496skills.sh installs
5parcadei avatarcomplete-skillparcadei/continuous-claude-v3A complete skill for E2E testing487skills.sh installs
6pedronauck avatarreactpedronauck/skillsReact 19 development under the React Compiler. Use when writing React components or hooks, deciding whether a useMemo/useCallback/memo belongs in the code, diag473skills.sh installs