Skip to content

Patterns for real-infrastructure .NET integration tests using Testcontainers instead of mocks.

CCM score
43 of 100
skills.sh installs
573
GitHub stars
94
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers spinning up real databases, caches, and message brokers in Docker containers for .NET tests
  • Includes SQL Server, PostgreSQL, and MySQL examples, plus Redis, RabbitMQ, and Kafka patterns in reference files
  • Enforces test isolation with fresh containers or truncated tables, random port mapping, and disposal in DisposeAsync
  • Designed for .NET teams that need data access and migration tests to exercise real SQL behavior

Install

$ npx -y skills add wshaddix/dotnet-skills --skill testcontainers -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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();

Details

Repository
github.com/wshaddix/dotnet-skills
Categories
Testing & QA, .NET & C#, Databases
First seen
Jun 3, 2026

More from wshaddix/dotnet-skills

All 13

Similar to Testcontainers

More Testing & QA