Skip to main content

Getting started

Installation

  1. Install the aweXpect nuget package

    dotnet add package aweXpect
  2. Add the following using statement:

    using aweXpect;

    This brings the static Expect class and lots of extension methods into scope.

  3. Simplify expectations (optional)
    If you want to simplify the assertions, you can add a global using static aweXpect.Expect; statement anywhere in your test project. This allows writing a more concise syntax:

    //    ↓ Default behaviour
    await Expect.That(subject).IsTrue();
    await That(subject).IsTrue();
    // ↑ With global static

Write your first expectation

Write your first expectation:

[Fact]
public async Task SomeMethod_WhenInputIsInvalid_ShouldReturnFalse()
{
bool result = SomeMethod("invalid input");

await Expect.That(result).IsFalse();
}

If it fails, it will throw a framework-specific exception with the following message:

Expected result to
be False,
but it was True

Add a reason

You can add a reason for all expectations, that will be included in the exception message:

[Fact]
public async Task SomeMethod_WhenInputIsInvalid_ShouldReturnFalse()
{
bool result = SomeMethod("invalid input");

await Expect.That(result).IsFalse().Because("the input was invalid");
}

This will result in

Expected result to
be False, because the input was invalid,
but it was True

Migration

We added support to migrate from other testing frameworks.

  1. Temporarily install the aweXpect.Migration package Nuget in the test project and add the following global using statements in the test project:

    global using System.Threading.Tasks;
    global using aweXpect;
  2. Depending on the framework, the assertions will be marked with a warning:

    • For FluentAssertions:
      All usages of .Should() will be marked with aweXpectM002: fluentassertions should be migrated to aweXpect
    • For Xunit:
      All usages of Assert will be marked with aweXpectM003: Xunit assertions should be migrated to aweXpect
  3. Most warnings can be automatically fixed with a code fix provider. Make sure to await all migrated expectations (fix aweXpect0001: Expectations must be awaited or verified).

  4. Fix the remaining warnings manually.

  5. Remove the aweXpect.Migration package again.

Detecting test frameworks

We support a lot of different unit testing frameworks:

When you have a reference to the corresponding test framework assembly, we will automatically throw the corresponding exceptions.