Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Updated Wiki: Home

$
0
0

Project Description

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. We currently use it in all our internal and client projects, and it is even used in the NCQRS project.

Why another framework?

We primarily use Visual Studio 2010’s own testing framework and were not satisfied by other similar frameworks. The best one we ran into missed a nice natural way for specifying the reason that is displayed when an assertion failed. Moreover, we like to be able to easily add domain-specific assertions without having to subclass a whole bunch of obscure interfaces and abstract classes. In the beginning of 2010, after having used the framework internally for almost a year, we decided to make it public and rebrand it as Fluent Assertions.

Example

// Verifying that a string begins, ends and contains a particular phrase.
string actual = "ABCDEFGHI";
actual.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

// Verifying that the collection contains a specified number of elements
// and that all elements match a predicate.
IEnumerable collection = new[] { 1, 2, 3 }; collection.Should().HaveCount(4, "because we thought we put three items in the collection"))
collection.Should().Contain(i => i > 0); // Verifying that a particular business rule is enforced using exceptions. var recipe = new RecipeBuilder() .With(new IngredientBuilder().For("Milk").WithQuantity(200, Unit.Milliliters)) .Build(); Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon); action .ShouldThrow<RuleViolationException>() .WithMessage("Cannot change the unit of an existing ingredient") .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity);
The nice thing about the second failing example is that it will throw an exception with the message

"Expected <4> items because we thought we put three items in the collection, but found <3>."

This should keep you from having to start the debugger to figure out what went wrong. This is one of the fundamental principles we think Fluent Assertions should help you with. Note that you don't need to include the word because explicitly. The framework will prepend your phrase with it automatically.

News

February 27th, 2011
Another update with lots of community requests. Read more about it over here.
January 15th, 2011
You can now download the latest version directly from within Visual Studio by using the NuGet package manager.
 
January 1st, 2011
Fluent Assertions 1.3.0 has been released with many improvements, event monitoring extensions and strong naming. More importantly, it is no longer linked to a particular version of NUnit, XUnit or MSTest.
 
August 27th, 2010
Fluent Assertions 1.2.3 has been released. It's another small release with some minor additions and bug fixes.  
 
June 29th, 2010
Fluent Assertions 1.2.2 has been released. It's a small release to fix some issues. Read more about it here

May 12th, 2010
Small release to fix an issue with enumerables that use the yield keyword. Now includes separate assemblies for different unit testing frameworks, including NUnit 2.5.5.10112.

April 12th, 2010
Fluent Assertions 1.2 has been released. Read more about it here

March 5th, 2010
We've worked hard to add some important missing features that we really needed, and also improve resilience against illegal arguments such as an empty collection or null. You can find it here: Fluent Assertions release 1.1.

Who are we?

We are a bunch of developers working for Aviva Solutions who highly value software quality, in particular

Viewing all articles
Browse latest Browse all 1402

Trending Articles