Share feedback
Answers are generated based on the documentation.

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 WebApplicationFactory to configure test dependencies with Testcontainers
  • Manage container lifecycle with xUnit's IAsyncLifetime

Prerequisites

Note

If you're new to Testcontainers, visit the Testcontainers overview to learn more about Testcontainers and the benefits of using it.

Modules

  1. Create the project

    Set up an ASP.NET Core Razor Pages project with integration test dependencies.

  2. Write tests

    Replace SQLite with a real Microsoft SQL Server using Testcontainers for .NET.

  3. Run tests

    Run the Testcontainers-based integration tests and explore next steps.