Getting started
Installation
-
Install the
aweXpectnuget packagedotnet add package aweXpect -
Add the following
usingstatement:using aweXpect;This brings the static
Expectclass and lots of extension methods into scope. -
Simplify expectations (optional)
If you want to simplify the assertions, you can add aglobal using static aweXpect.Expect;statement anywhere in your test project. This allows writing a more concise syntax:// ↓ Default behaviourawait 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 tobe 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 tobe False, because the input was invalid,but it was True