Soenneker.TestHosts.Unit 11.0.233

Prefix Reserved
dotnet add package Soenneker.TestHosts.Unit --version 11.0.233
                    
NuGet\Install-Package Soenneker.TestHosts.Unit -Version 11.0.233
                    
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.233" />
                    
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.233" />
                    
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.233
                    
#r "nuget: Soenneker.TestHosts.Unit, 11.0.233"
                    
#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.233
                    
#: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.233
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.TestHosts.Unit&version=11.0.233
                    
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.233 0 11/15/2026
11.0.232 2,171 11/13/2026
11.0.231 3,170 11/11/2026
11.0.229 54 11/11/2026
11.0.228 967 11/11/2026
11.0.226 1,594 11/11/2026
11.0.225 2,723 11/11/2026
11.0.224 51 11/11/2026
11.0.223 16,895 11/7/2026
11.0.222 2,947 11/7/2026
11.0.221 6,863 11/4/2026
11.0.220 1,678 11/3/2026
11.0.219 3,995 11/3/2026
11.0.218 2,970 11/3/2026
11.0.217 1,238 11/3/2026
11.0.216 3,159 11/2/2026
11.0.215 6,997 10/29/2026
11.0.214 5,797 10/27/2026
11.0.213 6,158 10/26/2026
11.0.212 105 10/26/2026
Loading failed

Update dependency Soenneker.Serilog.Sinks.TUnit to 11.0.172 (#210)