Using FluentAssertions in dotnet core unit tests
December 01, 2016 by Anuraj
dotnet core FluentAssertions xUnit
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 :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub