MetricsAssertions.TUnit 0.1.0

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

MetricsAssertions.TUnit

NuGet License: MIT .NET

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

TUnit-native fluent assertions over System.Diagnostics.Metrics instruments, built on the first-party MetricCollector testing primitive. AOT-compatible, trimmable, no runtime reflection in the assertion path.

What ships

Fluent Assert.That(...).Has* assertions over three receivers:

Receiver Assertions
InstrumentCapture counter / up-down-counter totals, measurement count, emptiness, last value, tag presence
MeasurementSet totals, counts, histogram sum / average / range, exact and order-insensitive samples, tag-consistency
MeterCapture per-instrument totals, counts, and tag presence by name

The framework-agnostic core (MetricsAssertions) ships the InstrumentCapture / MeterCapture capture types, the queryable MeasurementSet, MeterInspector, and the CapturedMeasurement record (instrument name, value projected to double, tags, timestamp).

Install

dotnet add package MetricsAssertions.TUnit

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

Quick start

using System.Diagnostics.Metrics;
using MetricsAssertions;

using var meter = new Meter("MyCompany.Orders");
var placed = meter.CreateCounter<long>("orders.placed");
using var capture = InstrumentCapture.Of(placed);

placed.Add(1);
placed.Add(1);

await Assert.That(capture).HasMeasurementCount(2);

The full reference is in the GitHub README.

License

MIT.

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.1.0 51 6/7/2026
0.0.1 94 6/7/2026

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

The full surface: a queryable `MeasurementSet`, multi-instrument `MeterCapture`, meter-introspection
`MeterInspector`, baseline deltas, and the complete `Assert.That` assertion vocabulary across all three.

### Added

- **`MeasurementSet` (core):** an immutable, queryable set of captured measurements with counter-style
 (`Total`) and histogram-style (`Sum`/`Min`/`Max`/`Average`) aggregates, raw `Values`/`All`, ordered and
 order-insensitive sample comparisons, tag and instrument narrowing (`Tagged`/`ForInstrument`), range and
 tag predicates, and a deterministic `ToSnapshotString` projection.
- **`MeterCapture` (core):** a meter-wide bundle composed from per-instrument captures, built fluently
 with `For` + `Add`, queried per instrument or across all via `Measurements`, with `RecordObservable`
 for observable gauges.
- **`MeterInspector` (core):** discovers which instruments a meter publishes
 (`PublishedInstrumentNames`/`IsPublished`/`PublishesAll`) via a short-lived `MeterListener`.
- **`InstrumentCapture` (core):** expanded with `OfName`/`OfObservable` construction, `Total`/`LastValue`,
 tag queries (`Tagged`/`HasMeasurementTagged`), baseline deltas (`Snapshot`/`Since` + `MeasurementBaseline`),
 `RecordObservable`, and `WaitForAsync`.
- **`MetricsAssertions.TUnit` (adapter):** the full `Assert.That(...).Has*` vocabulary (counter and
 up-down-counter totals, measurement counts, emptiness, last value, histogram sum/average/range, exact and
 order-insensitive sample sets, and tag-consistency) over `InstrumentCapture`, `MeasurementSet`, and
 `MeterCapture`.
- **Failure diagnostics:** every assertion dumps the captured measurements (instrument, value, tags,
 timestamp) under the failure, so a mismatch shows what was actually recorded, not only the mismatched
 scalar.
- **Hardening:** tolerance arguments are validated (finite, non-negative), inverted range bounds are
 rejected, baselines are bound to their originating capture, duplicate `MeterCapture` instrument names
 dispose the prior capture, and unknown meter-capture instruments fail as assertions rather than throwing.

### Changed

- **Breaking:** `InstrumentCapture.Measurements` now returns a `MeasurementSet` instead of
 `IReadOnlyList<CapturedMeasurement>`. Use `Measurements.All` for the underlying list, or the new query
 surface directly.