Showing posts from 2022

Better assertions for your unit tests

This article is part of the  C# Advent calendar . During the event, two new articles are posted each day by authors throughout the community. Introduction Unlike many other developers, I do like unit tests. These tests have saved my professional life more than once. Without them, I would have pushed very bad mistakes to the remote codebase. As much as I like unit tests, I don't like the way assertions work in the unit testing frameworks in both xUnit and MSTest. In my opinion, the assertions do not express clearly what I want to assert and I also have to explain the correct order of arguments for Assert to new developers over and over again. For a couple of years, I started using another component for this: Fluent Assertions . In this blog post, I will show you how you can create more readable assertions using this package. Installation In order the start using the package, you have to install it from the NuGet-repository.