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!
Have you ever had to write and rewrite boilerplate code to set up a database, reset data between each test, or tear down containers? All that setup required to keep your integration tests fully isolated, and ensure their maintainability, reproducibility, and efficiency.
NotoriousTests removes the need to build all of that yourself.
The concept is simple:
- Create an infrastructure and implement its initialization, reset, and destruction logic.
- Add it to an environment.
- Access it directly from your integration tests.
NotoriousTests will automatically manage the lifecycle of your infrastructures.
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
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.
Now, let's create a basic web application for our tests.
public class SampleWebApp : WebApplication<Program>
{
// Override WebApplicationFactory methods.
}❗ This is a
WebApplicationFactorycustomized forNotoriousTest.
📌 What this does:
- Defines a minimal web application factory for testing.
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.
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.).
Now, let's run the test:
dotnet testYou should see something like:
Passed! 1 test successful.If everything works, congrats! 🎉 You’ve successfully set up NotoriousTest.
- 📖 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.
You can find the changelog here.
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:
- GitHub Issues: Open an issue to report a problem, request a feature, or share an idea.
- Email: briceschumacher21@gmail.com
- LinkedIn : Brice SCHUMACHER
The discussions tabs is now opened ! Feel free to tell me if you use the package here : #1 !
- 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.
