Rocket.Surgery.Extensions.Testing 11.0.2

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

Rocket Surgery Testing

Test helpers for .NET: a test base class that sends Serilog output to your test framework and captures log events for assertions, auto-mocking containers for FakeItEasy and NSubstitute, test data builders, and a harness for testing Roslyn source generators, analyzers and code fixes. TUnit and xUnit v3 are supported.

github-release-badge github-license-badge github-build-badge codecov-badge nuget-Rocket.Surgery.Extensions.Testing-badge

Documentation: docs/src/content/docs

Getting started

Add the package for your test framework. It brings in Rocket.Surgery.Extensions.Testing:

# TUnit
dotnet add package Rocket.Surgery.Extensions.Testing.TUnit

# xUnit v3
dotnet add package Rocket.Surgery.Extensions.Testing.XUnit3

Derive the test class from LoggerTest<TContext>. Logger writes to the current test's output, and CaptureLogs collects the events written until it is disposed:

using Serilog.Events;
using Rocket.Surgery.Extensions.Testing;

public class OrderServiceTests() : LoggerTest<TestRecord>(TestRecord.Create())
{
    [Test]
    public async Task Logs_a_warning_for_empty_orders()
    {
        using var capture = CaptureLogs(log => log.Level >= LogEventLevel.Warning, out var logs);

        Logger.Information("not captured: below the filter");
        Logger.Warning("order {OrderId} has no lines", 42);

        await Assert.That(logs.Count()).IsEqualTo(1);
    }
}

With Rocket.Surgery.Extensions.Testing.FakeItEasy, derive from AutoFakeTest<TContext> instead. AutoFake.Resolve<T>() builds the class under test and fakes every dependency the container can't construct, returning the same fake each time within a test:

using FakeItEasy;
using Rocket.Surgery.Extensions.Testing;

public class CheckoutTests() : AutoFakeTest<TestRecord>(TestRecord.Create())
{
    [Test]
    public async Task Charges_the_customer()
    {
        var payments = AutoFake.Resolve<IPaymentGateway>();
        var checkout = AutoFake.Resolve<CheckoutService>();

        await checkout.CompleteAsync(orderId: 42);

        A.CallTo(() => payments.ChargeAsync(42, A<CancellationToken>._)).MustHaveHappenedOnceExactly();
    }
}

See the quickstart, auto-mocking, fixtures and source generator testing pages.

Packages

Package NuGet What it does
Rocket.Surgery.Extensions.Testing nuget-Rocket.Surgery.Extensions.Testing-badge LoggerTest<TContext>, which wires Serilog to the test output and captures log events, and the DryIoc helpers the mocking packages build on
Rocket.Surgery.Extensions.Testing.TUnit nuget-Rocket.Surgery.Extensions.Testing.TUnit-badge TestRecord, the test context for TUnit
Rocket.Surgery.Extensions.Testing.XUnit3 nuget-Rocket.Surgery.Extensions.Testing.XUnit3-badge XUnitTestContext, the test context for xUnit v3
Rocket.Surgery.Extensions.Testing.FakeItEasy nuget-Rocket.Surgery.Extensions.Testing.FakeItEasy-badge AutoFakeTest<TContext>: a DryIoc container that resolves the system under test and fakes missing dependencies with FakeItEasy
Rocket.Surgery.Extensions.Testing.NSubstitute nuget-Rocket.Surgery.Extensions.Testing.NSubstitute-badge AutoSubstituteTest<TContext>: the same container with NSubstitute substitutes
Rocket.Surgery.Extensions.Testing.Fixtures nuget-Rocket.Surgery.Extensions.Testing.Fixtures-badge ITestFixtureBuilder and the With helpers for hand-written test data builders
Rocket.Surgery.Extensions.Testing.AutoFixtures nuget-Rocket.Surgery.Extensions.Testing.AutoFixtures-badge Source generator that writes a fixture builder from a constructor, marked with [AutoFixture]
Rocket.Surgery.Extensions.Testing.SourceGenerators nuget-Rocket.Surgery.Extensions.Testing.SourceGenerators-badge GeneratorTestContextBuilder: compiles sources, runs generators, analyzers, code fixes and refactorings, and snapshots the results with Verify

Rocket.Surgery.Extensions.Testing.Analyzers comes in with Rocket.Surgery.Extensions.Testing, so you don't reference it yourself. It ships no analyzer rules at present.

Contributing

Run mise install before building: it installs the .NET SDK and the extra .NET 10 runtime that the net10.0 tests run on (.config/mise.toml). global.json pins the same SDK, so a dotnet outside mise fails fast unless that SDK is installed.

On macOS, the first mise install of a new .NET SDK can overwrite the shared ~/.local/share/mise/dotnet-root/dotnet host in place, and macOS then kills every dotnet command (SIGKILL). Replace the host with a fresh copy to fix it:

cd ~/.local/share/mise/dotnet-root && cp -p dotnet dotnet.fresh && mv -f dotnet.fresh dotnet
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Rocket.Surgery.Extensions.Testing:

Package Downloads
Rocket.Surgery.Extensions.Testing.FakeItEasy

AutoFakeTest<TContext> and AutoFake, a DryIoc container that resolves the class under test and fills in FakeItEasy fakes for dependencies it can't construct. Also initializes Verify.FakeItEasy.

Rocket.Surgery.Extensions.Testing.XUnit

Package Description

Rocket.Surgery.Extensions.Testing.XUnit3

XUnitTestContext, the xUnit v3 test context for LoggerTest<TContext>, which writes Serilog output to the current test's output through ITestContextAccessor.

Rocket.Surgery.Extensions.Testing.TUnit

TestRecord, the TUnit test context for LoggerTest<TContext>, which writes Serilog output to the current TUnit test's output.

Rocket.Surgery.Extensions.Testing.Moq

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.2 0 11/26/2026
11.0.1 4,245 10/28/2026
11.0.0 536 10/22/2026
11.0.0-beta.1 136 10/22/2026
10.0.6 3,219 7/4/2026
10.0.5 2,165 6/28/2026
10.0.4 172 6/28/2026
10.0.4-beta.1 118 6/28/2026
10.0.3 203 6/28/2026
10.0.3-beta.55 143 6/28/2026
10.0.3-beta.54 131 6/28/2026
10.0.3-beta.53 115 6/26/2026
10.0.3-beta.52 129 6/24/2026
10.0.2 13,964 5/16/2026
10.0.1 43,772 3/2/2026
10.0.0-beta.2 72,729 9/15/2025
10.0.0-beta.1 615 9/10/2025
9.0.5 244,176 2/25/2025
9.0.4 2,374 1/24/2025
9.0.3 4,301 12/17/2024
Loading failed