testcontainers-shared-fixture

Share one MongoDbContainer per xUnit collection with GUID-based per-test databases.

Updated Mar 18, 2022
One-click install
npx skills add https://github.com/mpaulosky/dotfiles --skill testcontainers-shared-fixture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testcontainers-shared-fixture
Source: https://github.com/mpaulosky/dotfiles/tree/main/.copilot/skills/testcontainers-shared-fixture
Command: npx skills add https://github.com/mpaulosky/dotfiles --skill testcontainers-shared-fixture

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many xUnit integration test classes each start their own MongoDbContainer which multiplies startup time and inflates CI run durations; this pattern reduces repeated container startups by sharing a single Testcontainers MongoDB instance per xUnit collection while preserving test isolation.

Core Features & Use Cases

  • Shared Fixture Lifecycle: Use a MongoDbFixture implementing IAsyncLifetime to start and stop one MongoDbContainer per xUnit collection.
  • Collection-level Parallelism: Define ICollectionFixture-based collections so related test classes share a container while different collections run in parallel.
  • Per-test Isolation: Create unique databases per test method using GUID-based names to maintain isolation without per-class containers.
  • CI Performance: Configure xunit.runner.json to enable collection-level parallelization and dramatically reduce total test startup time.
  • Practical Use Case: Ideal for .NET integration tests that use Testcontainers and MongoDB where dozens of test classes previously created slow sequential containers.

Quick Start

Convert per-class MongoDbContainer setups into a single MongoDbFixture shared via ICollectionFixture and enable parallelizeTestCollections in xunit.runner.json to cut container startup overhead.

Frequently Asked Questions about testcontainers-shared-fixture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I share a single MongoDB container across xUnit test classes?

Share a MongoDB container by defining a fixture class that implements IAsyncLifetime and registering it via ICollectionFixture, allowing related test classes to reuse a single Testcontainers instance and reduce CI startup overhead.

Why does starting a Testcontainers MongoDB instance per test class slow down my CI pipeline?

Starting a MongoDB container per test class multiplies container startup time sequentially, inflating CI run durations; sharing one container per xUnit collection via a shared fixture dramatically reduces this repeated startup overhead.

Can I maintain test isolation when sharing a MongoDB container across xUnit collections?

Yes, test isolation is maintained by creating unique databases for each test method using GUID-based names, ensuring tests do not interfere with each other while sharing a single MongoDB container instance.

How do I enable collection-level parallelism for Testcontainers MongoDB integration tests in .NET?

Enable collection-level parallelism by configuring xunit.runner.json to run collections in parallel, allowing different xUnit collections with separate shared MongoDB fixtures to execute tests concurrently and optimize CI time.

Does this shared fixture approach work with existing per-class MongoDB Testcontainers setups?

Yes, convert existing per-class MongoDB container setups into a single MongoDbFixture shared via ICollectionFixture, then enable parallelizeTestCollections in xunit.runner.json to cut container startup overhead while preserving isolation.