Skills

Testcontainers Integration Tests

Write integration tests using TestContainers for .NET with xUnit.

Install

npx skills add Aaronontheweb/dotnet-skills --skill testcontainers-integration-tests -g -a claude-code -y
Category
Testing
Updated
7d ago
License
MIT
Context cost
Mediumabout 2,358 tokens
Runs scripts
No, instructions only

What it does

Write integration tests using TestContainers for .NET with xUnit. Covers infrastructure testing with real databases, message queues, and caches in Docker containers instead of mocks.

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

Reference Files

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

TestContainers 4.x API

This skill targets TestContainers 4.x with the 3.0+ module builder API. The pre-3.0 types were renamed and removed, so code that uses TestcontainersBuilder<T> or TestcontainersContainer does not compile against the modern packages:

Old (pre-3.0)New (3.0+)
new TestcontainersBuilder<T>()Module builder (e.g. new PostgreSqlBuilder(...)) or new ContainerBuilder(...)
TestcontainersContainerDockerContainer / module container (e.g. PostgreSqlContainer)
TestcontainersNetworkBuilderNetworkBuilder
GetMappedPublicPort(port)GetMappedPublicPort(port) (still available)
Read the whole SKILL.md on GitHub

More in Testing