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.