Testing an ASP.NET Core web app with Testcontainers
Table of contents
Learn how to test an ASP.NET Core web app using Testcontainers for .NET
with a real Microsoft SQL Server instance instead of SQLite.
Time to complete
25 minutes
In this guide, you'll learn how to:
- Use Testcontainers for .NET to spin up a Microsoft SQL Server container for integration tests
- Replace SQLite with a production-like database provider in ASP.NET Core tests
- Customize
WebApplicationFactoryto configure test dependencies with Testcontainers - Manage container lifecycle with xUnit's
IAsyncLifetime
Prerequisites
- .NET 8.0+ SDK
- A code editor or IDE (Visual Studio, VS Code, Rider)
- A Docker environment supported by Testcontainers. For details, see the Testcontainers .NET system requirements.
NoteIf you're new to Testcontainers, visit the Testcontainers overview to learn more about Testcontainers and the benefits of using it.
Modules
- Create the project
Set up an ASP.NET Core Razor Pages project with integration test dependencies.
- Write tests
Replace SQLite with a real Microsoft SQL Server using Testcontainers for .NET.
- Run tests
Run the Testcontainers-based integration tests and explore next steps.