MetricsAssertions 0.1.0
Prefix Reserveddotnet add package MetricsAssertions --version 0.1.0
NuGet\Install-Package MetricsAssertions -Version 0.1.0
<PackageReference Include="MetricsAssertions" Version="0.1.0" />
<PackageVersion Include="MetricsAssertions" Version="0.1.0" />
<PackageReference Include="MetricsAssertions" />
paket add MetricsAssertions --version 0.1.0
#r "nuget: MetricsAssertions, 0.1.0"
#:package MetricsAssertions@0.1.0
#addin nuget:?package=MetricsAssertions&version=0.1.0
#tool nuget:?package=MetricsAssertions&version=0.1.0
MetricsAssertions
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
InstrumentCapturecaptures a referenceable, observable, or by-name instrument (Of/OfObservable/OfName) viaMetricCollector<T>, with totals, last value, tag queries, baseline deltas (Snapshot/Since), andWaitForAsync.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) andMeterInspector(instrument discovery).CapturedMeasurement(instrument name, value projected todouble, 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 | 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. |
-
net10.0
- Microsoft.Extensions.Diagnostics.Testing (>= 10.6.0)
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.
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.