MetricsAssertions 0.3.0

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

MetricsAssertions

NuGet License: MIT .NET

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

Framework-agnostic core for fluent metric-measurement assertions over System.Diagnostics.Metrics instruments, built on the first-party MetricCollector testing primitive. Test-framework assertion entry points live in adapter packages; MetricsAssertions.TUnit ships today.

What ships

  • InstrumentCapture captures a referenceable, observable, or by-name instrument (Of / OfObservable / OfName) via MetricCollector<T>, with totals, last value, tag queries, baseline deltas (Snapshot / Since), and WaitForAsync. The by-name captures (OfName, and MeterCapture.For) take an optional meter scope (v0.2.0+) so a meter created by an IMeterFactory (the ASP.NET Core DI metrics path) can be captured.
  • MeasurementSet: an immutable, queryable set of measurements with counter and histogram aggregates, sample comparisons, tag and instrument narrowing, and a deterministic snapshot projection.
  • MeterCapture (meter-wide capture across instruments) and MeterInspector (instrument discovery).
  • CapturedMeasurement (instrument name, value projected to double, tags, timestamp).

Install

# Most consumers install a test-framework adapter, which pulls this in transitively:
dotnet add package MetricsAssertions.TUnit

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 (1)

Showing the top 1 NuGet packages that depend on MetricsAssertions:

Package Downloads
MetricsAssertions.TUnit

TUnit-native fluent metric-assertion DSL over System.Diagnostics.Metrics instruments for .NET tests: Assert.That(capture) entry points generated via the GenerateAssertion source generator. Measurement capture is the first-party MetricCollector testing primitive wrapped in a per-test InstrumentCapture. Builds on the MetricsAssertions framework-agnostic core. AOT-compatible, trimmable, no runtime reflection in the assertion path.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 340 6/15/2026
0.2.0 1,444 6/12/2026
0.1.0 174 6/7/2026
0.0.1 208 6/7/2026

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

Minor release. Adds absolute-tolerance overloads to the value assertions, closing the asymmetry where the histogram aggregates (`HasSampleSum` / `HasSampleAverage`) accepted a tolerance but the value assertions compared doubles exactly. Purely additive; the `0.2.0` ApiCompat baseline is preserved.

### Added

- **`HasLastValue(double expected, double tolerance)`** on an `InstrumentCapture` asserts the most recent value within an absolute tolerance, the tolerant counterpart of `HasLastValue(double)` for gauges fed computed doubles (where `0.1 + 0.2 != 0.3` exact comparison flakes).
- **`HasSamples(IReadOnlyList<double> expected, double tolerance)`** and **`HasSamplesInAnyOrder(IReadOnlyList<double> expected, double tolerance)`** on a `MeasurementSet` assert the samples within an absolute per-sample tolerance, in order and order-independent respectively. The framework-agnostic core gains the matching `MeasurementSet.SamplesEqual(expected, tolerance)` / `SamplesEquivalentTo(expected, tolerance)` comparison primitives. Every tolerance overload rejects a non-finite or negative tolerance with `ArgumentOutOfRangeException`, so an invalid tolerance fails fast instead of silently matching everything (`NaN`) or nothing (negative).

### Documentation

- **`MeasurementSet.Total`** now documents that the sum is rounded to a `long` with banker's rounding (round half to even), so a `Counter<double>` with a fractional total is evaluated as an integer. For an exact fractional total, compare `Sum` directly or use `HasSampleSum(expected, tolerance)`.