Skip to content

A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.

License

Notifications You must be signed in to change notification settings

fluentassertions/fluentassertions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Extension methods to fluently assert the outcome of .NET tests

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.

About

A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 225

Languages