Posted by Anuraj on Thursday, December 1, 2016 Reading time :1 minute
This post is about using FluentAssertions in xUnit unit tests. Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. It has better support for exceptions and some other features that improves readability and makes it easier to write unit tests. In this post I am using ASPNET Yo man generator to create unit tests. And I have added FluentAssertions reference via project.json file.
Here is the project.json file.
Now in the unit test code, I have added two more unit test from FluentAssertions home page.
The first test is to verify that a string begins, ends and contains a particular phrase. And the second one is to verify that a collection contains a specified number of elements and that all elements match a predicate.
Now you can do a
dotnet restore command to restore the dependencies and run the unit tests with
dotnet test command. And here is the results.
Happy Programming :)