Share feedback
Answers are generated based on the documentation.

Getting started with Testcontainers for .NET

Table of contents

Learn how to create a .NET application and test database interactions using Testcontainers for .NET with a real PostgreSQL instance.
Time to complete 20 minutes

In this guide, you will learn how to:

  • Create a .NET solution with a source and test project
  • Implement a CustomerService that manages customer records in PostgreSQL
  • Write integration tests using Testcontainers and xUnit
  • Manage container lifecycle with IAsyncLifetime

Prerequisites

  • .NET 8.0+ SDK
  • A Docker environment supported by Testcontainers
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 a .NET solution with a PostgreSQL-backed customer service.

  2. Write tests

    Write integration tests using Testcontainers for .NET and xUnit with a real PostgreSQL database.

  3. Run tests

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