Free, MIT-licensed fluent assertions for .NET with familiar Should() syntax, deep object diffs, snapshot testing, and zero commercial license requirements.
- No commercial license requirement for commercial use.
- Familiar migration path: fluent
Should()API for xUnit, NUnit, and MSTest. - Deep diff output for
BeEquivalentTomismatches. - AOT-safe direction with optional generated reflection-free equivalency comparers.
dotnet add package Swevo.AutoAssertOptional companion packages:
dotnet add package Swevo.AutoAssert.Analyzers
dotnet add package Swevo.AutoAssert.Generator
dotnet add package Swevo.AutoAssert.AspNetCore
dotnet add package Swevo.AutoAssert.Jsonusing AutoAssert;
[Fact]
public void Order_total_is_calculated()
{
var order = new { Subtotal = 100m, Tax = 20m, Total = 120m };
order.Total.Should().Be(120m);
order.Should().BeEquivalentTo(new { Subtotal = 100m, Tax = 20m, Total = 120m });
}using AutoAssert;
"hello world".Should()
.NotBeNullOrEmpty()
.And.StartWith("hello")
.And.EndWith("world");
5.Should().BePositive().And.BeLessThan(10);using AutoAssert;
var actual = new OrderDto
{
Id = 42,
Customer = new CustomerDto { Name = "Ada" },
Lines = [new OrderLineDto { Sku = "ABC", Quantity = 2 }]
};
var expected = new
{
Id = 42,
Customer = new { Name = "Ada" },
Lines = new[] { new { Sku = "ABC", Quantity = 2 } }
};
actual.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());using AutoAssert;
using (new AssertionScope())
{
result.Name.Should().Be("Ada");
result.Age.Should().Be(30);
result.Email.Should().NotBeNullOrEmpty();
}using AutoAssert;
result.Should().MatchSnapshot(
scrub: SnapshotScrubbers.Combine(
SnapshotScrubbers.Guids(),
SnapshotScrubbers.IsoTimestamps()));AutoAssert is designed to keep common usage nearly identical:
| Scenario | FluentAssertions style | AutoAssert style |
|---|---|---|
| Basic value | value.Should().Be(42); |
value.Should().Be(42); |
| Null/empty | name.Should().NotBeNullOrEmpty(); |
name.Should().NotBeNullOrEmpty(); |
| Exception | act.Should().Throw<InvalidOperationException>(); |
act.Should().Throw<InvalidOperationException>(); |
| Equivalency | actual.Should().BeEquivalentTo(expected); |
actual.Should().BeEquivalentTo(expected); |
See deeper comparisons in docs/COMPARISON.md.
Copy/paste recipes for common test scenarios:
docs/RECIPES.md(collections, API payloads, async exceptions, snapshots)src/AutoAssert.AspNetCore/README.md(HTTP integration tests)src/AutoAssert.Json/README.md(raw JSON assertions)
| Package | Purpose |
|---|---|
Swevo.AutoAssert.Analyzers |
Compile-time diagnostics for assertion footguns. |
Swevo.AutoAssert.Generator |
Reflection-free generated equivalency comparers. |
Swevo.AutoAssert.AspNetCore |
Fluent HttpResponseMessage assertions for integration tests. |
Swevo.AutoAssert.Json |
Fluent assertions over raw JSON strings. |
See docs/COMPATIBILITY.md for package-by-package target frameworks and test framework support.
See CHANGELOG.md for version history and feature changes.
The repository now includes reusable go-to-market assets:
docs/NUGET-LISTING.mdfor listing copy and metadata guidance.docs/DISTRIBUTION.mdfor release promotion checklist.docs/METRICS.mdfor a simple download and retention measurement model.
MIT © Justin Bannister