This project is no longer maintained!
Consider using aweXpect instead...
This library is used to assert unit tests in natural language by specifying expectations. It tries to take the best from fluentassertions and TUnit and combine them to a new assertions library.
All expectations are completely async. This allows complete support of IAsyncEnumerable as well es HttpResponseMessage or similar async types.
No need to distinguish between action.Should().Throw() and await asyncAction.Should().ThrowAsync()!
By using await, the evaluation is only triggered after the complete fluent chain is loaded, which has some nice benefits:
- Becausecan be registered once as a general method that can be applied at the end of the expectation instead of cluttering all methods with the- becauseand- becauseArgsparameters
- WithCancellationcan also be registered at the end an applies a- CancellationTokento all async methods which allows cancellation of- IAsyncEnumerableevaluations
- Expectations can be combined directly (via Expect.ThatAll) instead of relying on global state (e.g. assertion scopes)
Fluentassertions have a proven way of extensibility via extension methods on .Should(). A similar approach is used here:
- Extensions can be written for new types (by writing a .Should()extension methods forIExpectSubjectThat<TType>)...
- and also for existing types (by writing an extension method on IThat<TType>)
By adding global using static Testably.Expectations.Expect; anywhere in the test project, that await can be part of the sentence of the expectation.
[Fact]
public async Task SomeMethod_ShouldThrowArgumentNullException()
{
  await That(SomeMethod).Should().Throw<ArgumentNullException>()
    .WithMessage("Value cannot be null")
    .Because("we tested the null edge case");
}Some simple benchmarks are available here.
