Skip to main content

aweXpect

Nuget Nuget

aweXpect is a fluent assertion library for .NET. It turns test verifications into readable sentences and produces failure messages that explain in plain English what was expected and what actually happened.

await Expect.That(message).IsEqualTo("It's a compliment");
Failure message
Expected that message
is equal to "It's a compliment",
but it was "It's a complement", which differs at index 12:
↓ (actual)
"…a complement"
"…a compliment"
↑ (expected)

Why aweXpect?​

The aweXpect.Core package is intentionally kept stable so extensions don't fight over versions. Ready-made extension packages cover JSON (aweXpect.Json), HTTP (aweXpect.Web), architecture tests (aweXpect.Reflection), file and time systems (aweXpect.Testably) and mocks (aweXpect.Mockolate).

Add expectations for any other type with extension methods on IThat<TType>:

public static AndOrResult<Track, IThat<Track?>> IsRadioFriendly(
this IThat<Track?> subject)
=> new(subject.Get().ExpectationBuilder.AddConstraint((it, grammars)
=> new IsRadioFriendlyConstraint(it, grammars)),
subject);

// usage
await Expect.That(track).IsRadioFriendly();

The full walkthrough is at Extending aweXpect.

Migrating from another assertion library?​

The aweXpect.Migration analyzer ships code-fix providers that rewrite most FluentAssertions and xunit.Assert call sites for you. See the migration guide for the full walkthrough.

Where to go next​

  • Getting Started: install the package and write your first expectation.
  • Migration: automated code fixes for moving from FluentAssertions or xunit.Assert.
  • How aweXpect works: awaiting, negation, combining, null, options, time and configuration.
  • Native AOT and trimming: how equivalency and event recording work in a test project published with trimming or Native AOT.
  • Extending aweXpect: add expectations for your own types using aweXpect.Core.