NotoriousTest.TestContainers 5.1.0

dotnet add package NotoriousTest.TestContainers --version 5.1.0
                    
NuGet\Install-Package NotoriousTest.TestContainers -Version 5.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NotoriousTest.TestContainers" Version="5.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NotoriousTest.TestContainers" Version="5.1.0" />
                    
Directory.Packages.props
<PackageReference Include="NotoriousTest.TestContainers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NotoriousTest.TestContainers --version 5.1.0
                    
#r "nuget: NotoriousTest.TestContainers, 5.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NotoriousTest.TestContainers@5.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NotoriousTest.TestContainers&version=5.1.0
                    
Install as a Cake Addin
#tool nuget:?package=NotoriousTest.TestContainers&version=5.1.0
                    
Install as a Cake Tool

Clean, isolated, and maintainable integration testing for .NET

NuGet NuGet Downloads License .NET Build Status GitHub stars

If you plan to use this NuGet package, let me know in the Tell me if you use that package ! discussion on Github ! Gaining insight into its usage is very important to me!

Summary

Purpose

Integration tests are valuable, but their setup is painful: starting databases, wiring connection strings, cleaning data between tests, tearing everything down — and ending up with orphan containers when a run crashes.

NotoriousTest handles all of that for you. The concept is simple:

  1. Describe each external dependency (database, container, web application…) as an infrastructure.
  2. Group them in an environment.
  3. Write integration tests against that environment.

NotoriousTest then manages the whole lifecycle:

  • ⚡ Initialize infrastructures before the tests — in parallel, in order when needed.
  • 🔗 Share configuration between them: your API receives the database connection string automatically.
  • 🧹 Reset them after each test, so every test starts from a clean state.
  • 🗑️ Destroy them at the end.
  • 🐶 Clean up after crashes thanks to DoggyDog, a watchdog process that removes whatever a killed run left behind.

It works with xUnit, NUnit, MSTest and TUnit, and ships ready-to-use infrastructures for SQL Server, PostgreSQL, SQLite, Docker containers, ASP.NET Core and Azure Functions.

Installation

Install the package matching your test framework:

Framework Package
xUnit (v3) NotoriousTest.XUnit
NUnit NotoriousTest.NUnit
MSTest NotoriousTest.MSTest
TUnit NotoriousTest.TUnit

Then the integrations you need:

dotnet add package NotoriousTest.XUnit
dotnet add package NotoriousTest.SqlServer
dotnet add package NotoriousTest.Web

Note: .NET 8 or higher is required. Docker-based infrastructures require Docker to be installed and running.

Quick Start

Let's test an ASP.NET Core API that saves users into SQL Server, against a real database running in Docker.

// The API under test — Program.cs
app.MapPost("/users", async (CreateUserRequest request, IConfiguration configuration) =>
{
    await using var connection = new SqlConnection(configuration.GetConnectionString("Default"));
    // INSERT INTO Users ...
    return Results.Created();
});

public partial class Program { } // makes Program visible to the test project

1. The Database

An infrastructure that starts SQL Server in a container and creates the schema:

public class DatabaseInfrastructure : SqlServerContainerInfrastructure
{
    public DatabaseInfrastructure(EnvironmentId environmentId, ITestLogger logger, IRegistry registry)
        : base(environmentId, logger, registry) { }

    public override async Task Initialize()
    {
        await base.Initialize(); // starts the container and creates the database

        await using var connection = GetDatabaseConnection();
        await connection.OpenAsync();

        await using var command = connection.CreateCommand();
        command.CommandText = "CREATE TABLE Users (Id INT IDENTITY PRIMARY KEY, Name NVARCHAR(100) NOT NULL)";
        await command.ExecuteNonQueryAsync();
    }
}

It publishes its connection string as ConnectionStrings:Default and empties every table after each test.

2. The Web Application

Your API, running in memory:

public class ApiApplication : WebApplication<Program>
{
}

It receives ConnectionStrings:Default from the database automatically — no configuration file needed.

3. The Environment

The environment lists the infrastructures your tests need:

public class ApiEnvironment : EnvironmentBase
{
    public ApiEnvironment(EnvironmentSettings settings, IWatchDog watchDog, IRegistry registry,
        IRuntime runtime, ITestLogger logger, IServiceProvider serviceProvider)
        : base(settings, watchDog, registry, runtime, logger, serviceProvider) { }

    protected override Assembly CurrentAssembly => Assembly.GetExecutingAssembly();

    public override Task ConfigureEnvironment()
    {
        AddInfrastructure<DatabaseInfrastructure>();
        this.AddWebApplication<ApiApplication>(); // always starts after the database
        return Task.CompletedTask;
    }
}

4. The Tests

public class UserTests : IntegrationTest<ApiEnvironment>
{
    public UserTests(XUnitFixture<ApiEnvironment> fixture) : base(fixture) { }

    [Fact]
    public async Task CreateUser_Should_InsertUserInDatabase()
    {
        HttpClient client = Environment.GetWebApplication().HttpClient!;

        await client.PostAsJsonAsync("users", new { Name = "Alice" });

        await using var connection = Environment.GetInfrastructure<DatabaseInfrastructure>().GetDatabaseConnection();
        await connection.OpenAsync();
        await using var command = connection.CreateCommand();
        command.CommandText = "SELECT COUNT(*) FROM Users";

        Assert.Equal(1, (int)(await command.ExecuteScalarAsync())!);
    }
}
dotnet test

That's it 🎉 The container starts before the first test, the table is emptied after each test, and everything is removed at the end — even if the run crashes.

👉 The full step-by-step walkthrough, with every using and an explanation of each step, is in the Example.

Multi-Framework Support

Infrastructures and environments are identical for every framework. Only the test base class changes:

Framework Base class Constructor
xUnit (v3) NotoriousTest.XUnit.IntegrationTest<TEnvironment> (XUnitFixture<TEnvironment> fixture)
NUnit NotoriousTest.NUnit.IntegrationTestBase<TEnvironment> parameterless
MSTest NotoriousTest.MSTest.IntegrationTestBase<TEnvironment> parameterless
TUnit NotoriousTest.TUnit.IntegrationTestBase<TEnvironment> (TUnitFixture<TEnvironment> fixture)
// NUnit
public class UserTests : NotoriousTest.NUnit.IntegrationTestBase<ApiEnvironment>
{
    [Test]
    public async Task CreateUser_Should_InsertUserInDatabase() { /* same as above */ }
}

// MSTest
[TestClass]
public class UserTests : NotoriousTest.MSTest.IntegrationTestBase<ApiEnvironment>
{
    [TestMethod]
    public async Task CreateUser_Should_InsertUserInDatabase() { /* same as above */ }
}

// TUnit
public class UserTests : NotoriousTest.TUnit.IntegrationTestBase<ApiEnvironment>
{
    public UserTests(TUnitFixture<ApiEnvironment> fixture) : base(fixture) { }

    [Test]
    public async Task CreateUser_Should_InsertUserInDatabase() { /* same as above */ }
}

Complete samples for each framework are available in the Samples folder.

Integrations

Package Provides
NotoriousTest.Web ASP.NET Core application running in memory.
NotoriousTest.Web.AzureFunctions Azure Functions host running locally.
NotoriousTest.SqlServer SQL Server — Docker container or existing server.
NotoriousTest.PostgreSql PostgreSQL — Docker container or existing server.
NotoriousTest.Sqlite SQLite — one database file per environment.
NotoriousTest.TestContainers Any Testcontainers container (Redis, RabbitMQ, Keycloak…).
NotoriousTest.Requirements.Docker Fails fast when Docker is not running.
NotoriousTest.Dependencies.Azure.FunctionCoreTools Installs the Azure Functions Core Tools when missing.

Need something else? Any class inheriting from Infrastructure is an infrastructure — see Core Concepts.

Resources & Community

Documentation

  • 🏗️ Core Concepts – Infrastructures, environments, lifecycle, DoggyDog, settings, dependency injection.
  • 🔌 Integrations – SQL Server, PostgreSQL, SQLite, Docker containers, Web, Azure Functions.
  • 📚 Example – A complete Web API + SQL Server setup, step by step.
  • 🏛️ Architecture Guidelines – Best practices for structuring your test setup.

Changelog

You can find the changelog here.

Contact

Have questions, ideas, or feedback about NotoriousTest? Feel free to reach out! I'd love to hear from you. Here's how you can get in touch:

The discussions tabs is now opened ! Feel free to tell me if you use the package here : https://github.com/Notorious-Coding/Notorious-Test/discussions/1 !

Other nugets i'm working on

  • NotoriousClient : Notorious Client is meant to simplify the sending of HTTP requests through a fluent builder and an infinitely extensible client system.
  • NotoriousModules : Notorious Modules provide a simple way to separate monolith into standalone modules.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on NotoriousTest.TestContainers:

Package Downloads
NotoriousTest.SqlServer

A SqlServer integration with NotoriousTest.

NotoriousTest.PostgreSql

A PostgreSql integration with NotoriousTest.

NotoriousTest.Database

A Database integration with NotoriousTest.

NotoriousTest.Web

Web integration tests support for NotoriousTest.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.1.0 65 9/30/2026
5.1.0-beta.191 42 9/29/2026
5.1.0-beta.189 44 9/29/2026
5.1.0-beta.187 77 9/28/2026
5.0.2 176 9/8/2026
5.0.2-beta.185 83 9/8/2026
5.0.2-beta.183 86 9/8/2026
5.0.1 184 6/26/2026
5.0.1-beta.174 89 6/26/2026
5.0.0 201 6/24/2026
5.0.0-beta.171 94 6/26/2026
5.0.0-beta.170 92 6/26/2026
5.0.0-beta.169 91 6/24/2026
5.0.0-beta.166 81 5/6/2026
5.0.0-beta.160 83 4/28/2026
5.0.0-beta.157 79 4/26/2026
5.0.0-beta.155 74 4/26/2026
4.1.1-beta.152 69 4/24/2026
4.1.0 275 4/23/2026
4.1.0-beta.149 81 4/22/2026
Loading failed