Soenneker.TestHosts.Unit 11.0.245

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.TestHosts.Unit

A TUnit-compatible shared test host with dependency injection, Serilog-to-test-output logging, Bogus, and AutoFaker.

Installation

dotnet add package Soenneker.TestHosts.Unit

Define a host

using Microsoft.Extensions.DependencyInjection;
using Soenneker.TestHosts.Unit;

public sealed class Host : UnitTestHost
{
    public override Task InitializeAsync()
    {
        Services.AddSingleton<IClock, TestClock>();
        Services.AddScoped<OrderService>();

        return base.InitializeAsync();
    }
}

Add registrations before calling base.InitializeAsync(). Initialization builds one service provider with scope validation enabled. Changes made to Services after that point do not alter the built provider.

Share it with TUnit

using Microsoft.Extensions.DependencyInjection;

[ClassDataSource<Host>(Shared = SharedType.PerTestSession)]
public sealed class OrderServiceTests
{
    private readonly Host _host;

    public OrderServiceTests(Host host)
    {
        _host = host;
    }

    [Test]
    public async Task Creates_an_order()
    {
        await using AsyncServiceScope scope = _host.ServicesProvider.CreateAsyncScope();
        var service = scope.ServiceProvider.GetRequiredService<OrderService>();

        var command = _host.AutoFaker.Generate<CreateOrder>();
        Order result = await service.Create(command);

        await Assert.That(result.Id).IsNotEqualTo(Guid.Empty);
    }
}

Create a scope when resolving scoped services; resolving one directly from the root provider fails because scope validation is enabled. ServicesProvider is available only after initialization.

Lifecycle

TUnit calls the host's asynchronous initialization and disposal through its data-source lifecycle. Disposing the host disposes the service provider and therefore any disposable services owned by it, then releases the logging pipeline. Test output written through ILogger<T> or Serilog is routed to the active TUnit context.

Faker and AutoFaker are created lazily and shared with the host. A per-test-session host therefore shares their randomizer state across its tests; do not rely on call order when tests execute concurrently.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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 Soenneker.TestHosts.Unit:

Package Downloads
Soenneker.Tests.HostedUnit

A fundamental test that stores the TestHost and provides synthetic inversion of control

Soenneker.Playwrights.TestHosts

A test host for automated testing with Playwright

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.245 4,606 11/20/2026
11.0.243 6,363 11/18/2026
11.0.241 1,436 11/18/2026
11.0.240 126 11/18/2026
11.0.239 91 11/18/2026
11.0.238 126 11/18/2026
11.0.237 3,883 11/18/2026
11.0.236 537 11/18/2026
11.0.235 3,517 11/17/2026
11.0.234 2,149 11/16/2026
11.0.233 5,552 11/15/2026
11.0.232 6,232 11/13/2026
11.0.231 3,258 11/11/2026
11.0.229 100 11/11/2026
11.0.228 1,027 11/11/2026
11.0.226 1,656 11/11/2026
11.0.225 2,788 11/11/2026
11.0.224 100 11/11/2026
11.0.223 16,919 11/7/2026
11.0.222 2,953 11/7/2026
Loading failed

Updated Soenneker.Serilog.Sinks.TUnit to 11.0.181