Skip to content
Fresh

ASP.NET Core testing

Back

Guides

Testing an ASP.NET Core web app with Testcontainers

Learn how to test an ASP.NET Core web app using Testcontainers for .NET with a real Microsoft SQL Server instance instead of SQLite.

C# Testing with Docker

25 minutes

1

Create the project

2

Write tests

3

Run tests

« Back to all guides

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 complete25 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.