Soenneker.Fixtures.Unit
11.0.829
Prefix Reserved
dotnet add package Soenneker.Fixtures.Unit --version 11.0.829
NuGet\Install-Package Soenneker.Fixtures.Unit -Version 11.0.829
<PackageReference Include="Soenneker.Fixtures.Unit" Version="11.0.829" />
<PackageVersion Include="Soenneker.Fixtures.Unit" Version="11.0.829" />
<PackageReference Include="Soenneker.Fixtures.Unit" />
paket add Soenneker.Fixtures.Unit --version 11.0.829
#r "nuget: Soenneker.Fixtures.Unit, 11.0.829"
#:package Soenneker.Fixtures.Unit@11.0.829
#addin nuget:?package=Soenneker.Fixtures.Unit&version=11.0.829
#tool nuget:?package=Soenneker.Fixtures.Unit&version=11.0.829
Soenneker.Fixtures.Unit
An extensible xUnit fixture that creates a dependency-injection container, configures injectable Serilog test output, and provides shared Bogus generators.
Install
dotnet add package Soenneker.Fixtures.Unit
Usage
Create a fixture and register its services in the constructor. xUnit calls InitializeAsync after construction, which builds the provider from those registrations.
using Microsoft.Extensions.DependencyInjection;
using Soenneker.Fixtures.Unit;
public sealed class TestFixture : UnitFixture
{
public TestFixture()
{
Services.AddSingleton<IClock, TestClock>();
Services.AddTransient<OrderService>();
}
}
Share the fixture through an xUnit collection:
using Microsoft.Extensions.DependencyInjection;
using Xunit;
[CollectionDefinition("unit")]
public sealed class UnitCollection : ICollectionFixture<TestFixture>;
[Collection("unit")]
public sealed class OrderServiceTests
{
private readonly TestFixture _fixture;
public OrderServiceTests(TestFixture fixture) => _fixture = fixture;
[Fact]
public void Creates_an_order()
{
OrderService service = _fixture.ServiceProvider!
.GetRequiredService<OrderService>();
string customerName = _fixture.Faker.Name.FullName();
Order request = _fixture.AutoFaker.Generate<Order>();
// exercise service
}
}
The fixture also registers its IInjectableTestOutputSink. Inject the current ITestOutputHelper into that singleton when a test class is constructed if logs should appear in that test's output:
using Serilog.Sinks.XUnit.Injectable.Abstract;
using Xunit;
IInjectableTestOutputSink sink = fixture.ServiceProvider!
.GetRequiredService<IInjectableTestOutputSink>();
sink.Inject(testOutputHelper);
Lifecycle and behavior
- Add or replace registrations before
InitializeAsyncruns. ChangingServicesafter the provider is built does not updateServiceProvider. Fakeris the Bogus generator owned byAutoFaker; use either property depending on whether a value or an entire object graph is needed.- The fixture owns the provider and injectable sink and disposes both during xUnit fixture teardown. Consumers should still dispose any scopes they create.
- Construction assigns the process-wide
Serilog.Log.Logger, and teardown flushes it. Use one shared fixture for a test collection or assembly; multiple fixture instances running in parallel can replace each other's global logger and route output to the wrong test.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Microsoft.Extensions.DependencyInjection (>= 11.0.0)
- Serilog.Sinks.XUnit.Injectable (>= 11.0.308)
- Soenneker.Utils.AutoBogus (>= 11.0.1014)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Fixtures.Unit:
| Package | Downloads |
|---|---|
|
Soenneker.Tests.FixturedUnit
A fundamental xUnit test that stores UnitFixture and provides synthetic inversion of control |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.829 | 123 | 11/19/2026 |
| 11.0.828 | 116 | 11/18/2026 |
| 11.0.826 | 106 | 11/18/2026 |
| 11.0.825 | 93 | 11/18/2026 |
| 11.0.824 | 113 | 11/18/2026 |
| 11.0.823 | 202 | 11/11/2026 |
| 11.0.822 | 114 | 11/11/2026 |
| 11.0.821 | 111 | 11/11/2026 |
| 11.0.820 | 115 | 11/11/2026 |
| 11.0.819 | 103 | 11/11/2026 |
| 11.0.818 | 129 | 11/11/2026 |
| 11.0.817 | 96 | 11/11/2026 |
| 11.0.816 | 121 | 11/11/2026 |
| 11.0.814 | 132 | 11/9/2026 |
| 11.0.813 | 184 | 11/3/2026 |
| 11.0.812 | 87 | 11/3/2026 |
| 11.0.811 | 82 | 11/3/2026 |
| 11.0.810 | 175 | 10/27/2026 |
| 11.0.809 | 90 | 10/26/2026 |
| 11.0.808 | 82 | 10/26/2026 |
Updated Serilog.Sinks.XUnit.Injectable to 11.0.308