Unit testing helper libraries
I have seen developers adding these two libraries to their unit tests to enhance the syntax and readability: Fluent Assertions and AutoFixture.
Fluent Assertions
Fluent implementation, also known as a fluent interface, is trying to make the code read like an English sentence. Take this example:
Is.Equal.To(…);
Some developers like to have the tests written in this way as it supports a more natural way of reading a test. Some like it for their own reasons.
FluentAssertions
is a popular library that integrates with all popular test frameworks among MSTest, Nunit, and xUnit to enable fluent interfaces. You can add it to your unit test project via NuGet under the name FluentAssertions
.
Let’s see how our code will be without and with the library:
// Without Assert.Equal(LAT, actualLat); // With actualLat.Should().Be(LAT);
But the previous snippet doesn’t show the true power of the library, so let’s do some...