The Principal Dev – Masterclass for Tech Leads

The Principal Dev – Masterclass for Tech LeadsNov 27-28

Join


Extension methods to fluently assert the outcome of .NET tests

Coveralls branch qodana GitHub Repo stars GitHub contributors GitHub last commit GitHub commit activity open issues

AboutDownloadHow To UseBuildingContributingVersioning

About

Fluent Assertions offers a comprehensive suite of extension methods that enable developers to naturally express the expected outcomes of TDD (Test-Driven Development) or BDD (Behavior-Driven Development) unit tests. By providing a more readable and intuitive approach to writing assertions, it streamlines the testing process and improves code clarity. It supports a wide range of .NET platforms, including .NET Framework 4.7, .NET Core 2.1, 3.0, and 6, as well as .NET Standard 2.0 and 2.1, ensuring compatibility across various modern development environments.

Xceed Partnership

Originally authored by Dennis Doomen with Jonas Nyrup as the productive side-kick. Xceed is now an official Partner to Fluent Assertions! Learn what this partnership means for our users. After extensive discussions with the Fluent Assertions team, we are thrilled about the future of the product and look forward to its continued growth and development.

Download

This library is available as a NuGet package on https://nuget.org. To install it, use the following command-line:

dotnet add package FluentAssertions

How do I use it

Fluent Assertions contains a tremendous amount of assertion methods that will make your unit tests easier to read and give you as much information possible upon failure. Consider this example.

IEnumerable<int> numbers = new[] { 1, 2, 3 };

numbers.Should().OnlyContain(n => n > 0);
numbers.Should().HaveCount(4, "because we thought we put four items in the collection");

This should give you the following failure:

Expected numbers to contain 4 item(s) because we thought we put four items in the collection, but found 3.

Visit https://www.fluentassertions.com for background information, usage documentation, an extensibility guide, support information and more tips & tricks.

Building

Install Visual Studio 2022 17.14+ or JetBrains Rider 2024.3 as well as the Build Tools 2022 (including the Universal Windows Platform build tools). You will also need to have .NET Framework 4.7 SDK and .NET 9.0 SDK installed. Check the global.json for the current minimum required version.

You can also build, run the unit tests and package the code using the following command-line:

build.ps1

Or, if you have, the Nuke tool installed:

nuke

Also try using --help to see all the available options or --plan to see what the scripts does.

What are these Approval.Tests?

This is a special set of tests that use the Verify project to verify whether you've introduced any breaking changes in the public API of the library.

If you've verified the changes and decided they are valid, you can accept them using AcceptApiChanges.ps1 or AcceptApiChanges.sh. Alternatively, you can use the Verify Support plug-in to compare the changes and accept them right from inside Rider. See also the Contribution Guidelines.

Contributing

Your contributions are always welcome! Please have a look at the contribution guidelines first.

Versioning

This library uses Semantic Versioning to give meaning to the version numbers. For the versions available, see the tags on this repository.

Credits

This library wouldn't have been possible without the following tools, packages and companies:

Powered By

License

Versions 8 and beyond are free for open-source projects and non-commercial use, but commercial use requires a paid license. Check out the license page for more information.

Version 7 will remain fully open-source indefinitely and receive bugfixes and other important corrections.

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.