#TIL Fluent Assertions Are Easy to Read

Finally getting back into my normal workload at iQmetrix after being away for two months, and I dive into a major integration test. Luckily we use Fluent Assertions so it was easy to get back into the swing of things!

Fluent Assertions is a library for .Net that allows you to write your coded test assertions in as close to plain english as possible. This is good for a number of reasons, my favorite being that you can treat your unit and integration tests as a form of “live documentation” – your tests describe how your code and features should work, and it has to be up to date or else it will fail miserably. Being able to write those assertions in something that’s easy to read without having intimiate knowledge of the system is an added bonus.

So with Fluent Assertions you can do things like this:

var booleanVariable = false;

See? Reads like a sentence! And while that’s pretty straightforward, it also supports more complicated assertions, such as

var complicatedList = new List<string>();
complicatedList.Should().Contain("At least one entry needs to match this");
complicatedList.Should().NotContain(item => item.Length != 5);

So you can do some pretty cool stuff with it. You can check out more about the library on their github site