📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you run integration tests against a real SQL Server in CI using Testcontainers?

Junior Theory Beginner

🎯 Key points

  • Testcontainers.MsSql MsSqlContainer with a pinned image
  • Start and dispose in an IAsyncLifetime collection fixture
  • Ryuk cleans up orphaned containers in CI
  • Feed connection string to WebApplicationFactory
  • Apply migrations once, reset with Respawn
  • Fail fast if Docker is unavailable on the agent
  • Real engine catches what in-memory hides

⏱ 30-second answer

Add the Testcontainers.MsSql package. In an xUnit collection fixture that implements IAsyncLifetime, build an MsSqlContainer with a pinned image, await StartAsync() in InitializeAsync, and await DisposeAsync() in teardown (Testcontainers' Ryuk reaper also removes orphaned containers if a CI job dies). Pass GetConnectionString() to a WebApplicationFactory by overriding configuration, apply EF Core migrations once, and reset data between tests with Respawn. If the container fails to start (for example the CI agent has no Docker), fail fast with a clear message rather than skipping. Each run gets a clean, real SQL Server, catching translation and constraint bugs that the in-memory provider hides.

🔍 What the interviewer is checking

Checks they can test data access against a real engine, not an in-memory fake

↩ Usually asked after

More in Containers

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me