October 19, 2015

Better Assertions with Shouldly

Shouldly is a open source assertion library for .NET which uses extension methods to simplify the assert syntax in Unit Tests. It can help to improve the readability of test code because the tests read like humans speak. Instead of asserting that one value satisfies the criteria of another we simply yet elegantly say such and succh value "should be" X criteria.
Take a look at the following examples:

Another nice feature of Shouldly is that it can work with just about any Unit Test Framework (NUnit, XUnit, MSTest). Shouldly is easy to use and even simpler to install makes testing code much clearer.
It is available on GitHub and as a Nuget package.
For more details and advanced options please see the full Pluralsight course on the subject Better Unit Test Assertions with Shouldly.