NotoriousTest 3.1.0

dotnet add package NotoriousTest --version 3.1.0
                    
NuGet\Install-Package NotoriousTest -Version 3.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" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NotoriousTest" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="NotoriousTest" />
                    
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 --version 3.1.0
                    
#r "nuget: NotoriousTest, 3.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@3.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&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=NotoriousTest&version=3.1.0
                    
Install as a Cake Tool

NuGet NuGet Downloads License .NET Build Status GitHub stars

Clean, isolated, and maintainable integration testing for .NET

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

๐Ÿšจ The problem with integration testing in .NET

When testing an application that relies on multiple infrastructures (databases, message buses, blob storage, FTP, SMTP...), the common approach looks like this:

  • Create a WebApplicationFactory and use it as a fixture.
  • Implement IAsyncLifetime to initialize and dispose of infrastructures.
  • Manage each infrastructure (SQL Server, RabbitMQ, Redis, MongoDB, etc.) within Initialize and Dispose.
  • Add specific setup code inside the test constructors.

๐Ÿ‘‰ This works for small projects, but as complexity increases, it becomes a nightmare:

๐Ÿ”ฅ The WebApplicationFactory turns into an unmanageable beast.
๐Ÿ”„ Everything needs to be manually refactored and structured โ†’ resulting in messy, hard-to-maintain code.
๐Ÿ—๏ธ Tests become slow to write and complex to maintain.
โณ Setup time skyrockets, reducing productivity.

And thatโ€™s the real problemโ€”integration tests are meant to ensure the quality of our code. But if they themselves become unmanageable, the enemy of our enemy becomes our enemy.

๐Ÿš€ NotoriousTest: The solution

NotoriousTest introduces a modular and structured approach to isolating and managing your test infrastructures effortlessly.

โœ… Each infrastructure (database, message bus, etc.) is encapsulated in its own class with a proper lifecycle (Init, Reset, Destroy).
โœ… Test environments are composable โ†’ you assemble infrastructures like Lego blocks.
โœ… Automatic reset between tests ensures proper isolation.
โœ… No need to bloat your WebApplicationFactory โ†’ each infrastructure is cleanly defined.
โœ… Works seamlessly with TestContainers, SQL Server, and more.

๐Ÿ‘‰ The result? A testing framework that is clean, modular, maintainable, and scalable.

Why use NotoriousTest

๐Ÿ”น Designed for complex integration tests
Seamlessly manage multiple infrastructures like databases, message buses, blob storage, and more, without turning your test setup into a nightmare.

๐Ÿ”น Fully isolated and resettable environments
Ensure clean, independent tests by automatically resetting infrastructures between each runโ€”no leftover data, no hidden side effects.

๐Ÿ”น Modular & reusable infrastructure components
Define each infrastructure separately and compose test environments like Lego blocks. No more bloated WebApplicationFactories!

๐Ÿ”น Effortless setup & minimal boilerplate
Forget complex test initialization logicโ€”NotoriousTest takes care of instantiating, resetting, and destroying your infrastructures automatically.

๐Ÿ”น Compatible with TestContainers & SQL Server
Seamlessly integrates with Dockerized test environments, allowing you to spin up databases, message queues, and more in seconds.

๐Ÿ”น Powered by XUnit & Async Support
Leverage the flexibility of XUnitโ€™s dependency injection and fully async infrastructure lifecycles for faster and more scalable tests.

Hello World

Setup

First, install NuGet. Then, install NotoriousTest from the package manager console:

PM> Install-Package NotoriousTest

Or from the .NET CLI as:

dotnet add package NotoriousTest

Define a Basic Infrastructure

An infrastructure represents an external dependency (database, message bus, etc.).

For now, weโ€™ll define an empty infrastructure to illustrate the setup. You can replace MyInfrastructure with any real infrastructure later.

public class MyInfrastructure : AsyncInfrastructure
{
    public override Task Initialize()
    {
        // Setup logic here (e.g., start a database, configure an API)
        Console.WriteLine($"Setup of {nameof(MyInfrastructure)}");
        return Task.CompletedTask;
    }

    public override Task Reset()
    {
        // Reset logic here (e.g., clear data, reset state)
        Console.WriteLine($"Reset of {nameof(MyInfrastructure)}");
        return Task.CompletedTask;
    }

    public override Task Destroy()
    {
        // Cleanup logic here (e.g., shut down services)
        Console.WriteLine($"Shutdown of {nameof(MyInfrastructure)}");
        return Task.CompletedTask;
    }
}

๐Ÿ“Œ What this does:

  • Defines a basic infrastructure with lifecycle methods.
  • This is where you would add setup logic for databases, APIs, queues, etc.

Create a Web Application

Now, let's create a basic web application for our tests.

public class SampleWebApp : WebApplication<Program>
{
    // Override WebApplicationFactory methods.
}

โ— This is a WebApplicationFactory customized for NotoriousTest.

๐Ÿ“Œ What this does:

  • Defines a minimal web application factory for testing.

Create a Test Environment

A test environment groups infrastructures together.

public class MyTestEnvironment : AsyncWebEnvironment
{
    public override async Task ConfigureEnvironmentAsync()
    {
        AddInfrastructure(new MyInfrastructure()); // Register the test infrastructure
        AddWebApplication(new SampleWebApp()); // Register the web app
    }
}

๐Ÿ“Œ What this does:

  • Registers MyInfrastructure and SampleWebApp inside the test environment.
  • Ensures all tests run in a clean and isolated setup.

Write your first test

Now, let's write a basic integration test using our environment.

public class MyIntegrationTests : AsyncIntegrationTest<MyTestEnvironment>
{
    public MyIntegrationTests(MyTestEnvironment environment) : base(environment) { }

    [Fact]
    public async Task ExampleTest()
    {
        // Retrieve the infrastructure
        var infra = await CurrentEnvironment.GetInfrastructureAsync<MyInfrastructure>();

        // Add test logic here (e.g., verify database state, call an API)

        Assert.NotNull(infra); // Basic validation to confirm setup works
    }
}

๐Ÿ“Œ What this does:

  • Retrieves the test infrastructure from the environment.
  • You can add real test logic (API calls, database assertions, etc.).

๐Ÿš€ Running Your First Test

Now, let's run the test:

dotnet test

Expected Output

You should see something like:

Passed! 1 test successful.

If everything works, congrats! ๐ŸŽ‰ Youโ€™ve successfully set up NotoriousTest.

Resources & Community

Documentation

  • ๐Ÿ“– Core Concepts โ€“ Learn how infrastructures and environments work.
  • โšก Advanced Features โ€“ Discover ordering, reset behaviors, and more. \
  • ๐Ÿ”Œ Integrations โ€“ See how to integrate SQL Server, TestContainers, and more.
  • ๐Ÿ“š Examples โ€“ Hands-on use cases with real-world setups.

Changelog

You can find the changelog here.

Contact

Have questions, ideas, or feedback about NotoriousTests? 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 net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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 (2)

Showing the top 2 NuGet packages that depend on NotoriousTest:

Package Downloads
NotoriousTest.TestContainers

A TestContainers integration with NotoriousTest.

NotoriousTest.PostgreSql

A PostgreSql integration with NotoriousTest.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 183 9/13/2025
3.1.0-beta.41 61 9/13/2025
3.1.0-beta.39 52 9/13/2025
3.1.0-beta.35 64 9/12/2025
3.0.0 212 9/11/2025
3.0.0-beta.28 86 2/22/2025
2.3.0 268 2/10/2025
2.3.0-beta.25 72 2/22/2025
2.3.0-beta.23 82 2/14/2025
2.3.0-beta.20 85 2/12/2025
2.3.0-beta.18 83 2/10/2025
2.3.0-beta.16 81 2/9/2025
2.3.0-beta.14 79 2/9/2025
2.3.0-beta.9 84 2/9/2025
2.2.0 154 2/9/2025
2.2.0-beta.7 76 2/9/2025
2.2.0-beta.5 76 2/9/2025
2.2.0-beta.4 82 2/9/2025
2.2.0-beta.2 77 2/9/2025
2.1.0 179 2/2/2025
2.0.0 182 9/4/2024
1.3.4 204 5/5/2024
1.3.3 184 5/5/2024
1.3.2 174 5/5/2024
1.2.1 209 1/17/2024
1.2.0 214 10/3/2023
1.1.0 177 9/28/2023
1.0.0 191 9/19/2023