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
<PackageReference Include="Rocket.Surgery.Extensions.Testing" Version="11.0.2" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing" Version="11.0.2" />
<PackageReference Include="Rocket.Surgery.Extensions.Testing" />
paket add Rocket.Surgery.Extensions.Testing --version 11.0.2
#r "nuget: Rocket.Surgery.Extensions.Testing, 11.0.2"
#:package Rocket.Surgery.Extensions.Testing@11.0.2
#addin nuget:?package=Rocket.Surgery.Extensions.Testing&version=11.0.2
#tool nuget:?package=Rocket.Surgery.Extensions.Testing&version=11.0.2
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.
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 | 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 | TestRecord, the test context for TUnit |
|
| Rocket.Surgery.Extensions.Testing.XUnit3 | XUnitTestContext, the test context for xUnit v3 |
|
| Rocket.Surgery.Extensions.Testing.FakeItEasy | AutoFakeTest<TContext>: a DryIoc container that resolves the system under test and fakes missing dependencies with FakeItEasy |
|
| Rocket.Surgery.Extensions.Testing.NSubstitute | AutoSubstituteTest<TContext>: the same container with NSubstitute substitutes |
|
| Rocket.Surgery.Extensions.Testing.Fixtures | ITestFixtureBuilder and the With helpers for hand-written test data builders |
|
| Rocket.Surgery.Extensions.Testing.AutoFixtures | Source generator that writes a fixture builder from a constructor, marked with [AutoFixture] |
|
| Rocket.Surgery.Extensions.Testing.SourceGenerators | 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 | Versions 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. |
-
net10.0
- DryIoc.dll (>= 6.0.0)
- DryIoc.Microsoft.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Rocket.Surgery.Extensions.Testing.Analyzers (>= 11.0.2)
- Serilog (>= 4.4.0)
- Serilog.Extensions.Logging (>= 10.0.0)
- Serilog.Sinks.Observable (>= 3.0.0)
- System.Reactive (>= 7.0.0)
-
net11.0
- DryIoc.dll (>= 6.0.0)
- DryIoc.Microsoft.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 11.0.0)
- Microsoft.Extensions.DependencyInjection (>= 11.0.0)
- Microsoft.Extensions.Logging (>= 11.0.0)
- Rocket.Surgery.Extensions.Testing.Analyzers (>= 11.0.2)
- Serilog (>= 4.4.0)
- Serilog.Extensions.Logging (>= 10.0.0)
- Serilog.Sinks.Observable (>= 3.0.0)
- System.Reactive (>= 7.0.0)
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 |