TracingAssertions.TUnit 0.2.0

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

TracingAssertions.TUnit

NuGet License: MIT .NET

Scope: Test projects only. Not intended for production code.

TUnit-native OpenTelemetry distributed-tracing (Activity / span) assertions for .NET tests. Fluent entry points over TUnit's Assert.That(...) pipeline for asserting on captured spans. AOT-compatible, trimmable, no runtime reflection in the assertion path.

What ships

Span assertions on Assert.That(span) where span is a System.Diagnostics.Activity:

Entry point Behavior
HasOperationName(name) Asserts the span's OperationName equals name (ordinal).
HasTag(key) Asserts a tag key is present (non-null value).
HasTagValue(key, value) Asserts the tag key matches value (compared by invariant ToString).
HasStatus(status) Asserts the span's Status equals the given ActivityStatusCode.
HasKind(kind) (v0.2.0+) Asserts the span's Kind equals the given ActivityKind (for example Server / Client).
IsChildOf(parent) Asserts a single-hop parent/child relationship in the same trace.
IsRoot() (v0.2.0+) Asserts the span has no parent.
HasEvent(name) / HasExceptionEvent() (v0.2.0+) Asserts the span carries an ActivityEvent with that name / the OpenTelemetry exception event.
SharesTraceWith(other) Asserts two spans share a TraceId.
HasSpan(operationName) / HasNoSpan(operationName) (HasNoSpan v0.2.0+) (on SpanCapture) Asserts the capture does / does not contain a span with that operation name.
HasSpanCount(int) (v0.2.0+) (on SpanCapture) Asserts the capture collected exactly that many spans.

The framework-agnostic core (TracingAssertions) ships SpanCapture for collecting spans from one or more ActivitySources via a raw ActivityListener (no OpenTelemetry SDK or NuGet runtime dependency), plus the query helpers FindByOperationName, FindByOperationNameAndTag, and ChildrenOf. ForSource / ForSources take an optional ActivitySamplingResult (v0.2.0+) to capture under a chosen sampling level.

Install

dotnet add package TracingAssertions.TUnit

Requirements: TUnit 1.54.0 or later, .NET 10. The framework-agnostic TracingAssertions core comes transitively.

Quick start

using System.Diagnostics;
using TracingAssertions;

using var capture = SpanCapture.ForSource("MyCompany.MyService");

using (var span = MyActivitySource.StartActivity("order.created"))
{
    await Assert.That(span).HasOperationName("order.created");
}

The full reference is in the GitHub README.

License

MIT. No runtime dependencies beyond the BCL.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 322 6/14/2026
0.1.2 1,369 6/6/2026
0.1.1 138 6/5/2026
0.1.0 244 6/4/2026
0.0.1 140 6/4/2026

View the rendered release notes: https://github.com/JohnVerheij/TracingAssertions.TUnit/releases/tag/v0.2.0

Minor release. Adds span and capture assertions for ASP.NET Core span testing, plus a sampling-control capture overload. Purely additive.

### Added

- **Span assertions:** `Assert.That(span).HasKind(ActivityKind)` (for example `Server` for an inbound request span), `IsRoot()` (no parent), `HasEvent(name)`, and `HasExceptionEvent()` (the OpenTelemetry `"exception"` event). The event assertions list the span's event names on failure.
- **Capture assertions:** `Assert.That(capture).HasNoSpan(operationName)` (the inverse of `HasSpan`, for asserting an operation was never traced) and `HasSpanCount(int)`.
- **`SpanCapture.ForSource(name, ActivitySamplingResult)`** and **`ForSources(ActivitySamplingResult, params string[])`** capture under a chosen sampling result. The existing parameterless forms still force `AllDataAndRecorded`. A lower result (for example `PropagationData`) lets a test exercise code that branches on `Activity.IsAllDataRequested`, with the documented caveat that an activity's effective sampling is the maximum across all active listeners, so this takes effect only when the capture is the sole listener.

### Changed

- Bumped `PackageValidationBaselineVersion` from `0.1.0` to `0.1.2` on both packages so ApiCompat strict-mode validates `0.2.0` against the most recently published baseline.