dotnetassertions

AOT-safe assertions for TUnit.

Nine small packages. Each adds a fluent Assert.That(...) vocabulary for one domain: logs, time, JSON, snapshots, math, traces, metrics, SSE, and gRPC. Reflection-free, MIT, test projects only.

Not a general-purpose assertion library. TUnit's own assertions stay as they are; these packages only add domain vocabulary on top of them.

The family

LogAssertions.TUnit

Assert on logs captured from ILogger via a fake collector.

await Assert.That(collector).HasLoggedOnly(LogLevel.Warning);

TimeAssertions.TUnit

TimeProvider state, timer leaks, and time budgets.

await Assert.That(fakeTime).HasAdvancedExactly(TimeSpan.FromMinutes(31));

JsonAssertions.TUnit

JSON path, value, and shape assertions over a document.

await Assert.That(json).HasJsonProperty("user.name");

SnapshotAssertions.TUnit

Text-snapshot and approval testing with scrubbers and diffs.

await Assert.That(actual).MatchesSnapshot();

MathAssertions.TUnit

Tolerance-aware numeric, geometry, and statistics checks.

await Assert.That(actual).IsApproximatelyEqualTo(target, tolerance: 1e-3);

TracingAssertions.TUnit

OpenTelemetry Activity, span, and tag assertions.

await Assert.That(span).HasOperationName("order.pipeline");

MetricsAssertions.TUnit

Metrics and instrument measurements via a collector.

await Assert.That(capture).HasCounterTotal(5);

SseAssertions.TUnit

Server-Sent Events wire-format and event-stream checks.

await Assert.That(body).HasSseEvent("tick").Exactly(3);

GrpcAssertions.TUnit

gRPC status codes, error details, and call assertions.

await Assert.That(() => client.GetOrderAsync(request, ct))
    .ThrowsGrpcException(StatusCode.Unavailable);