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.

Why another framework?

We primarily use MSTest from inside Visual Studio and were not satisfied by other similar frameworks. The best one we ran into, Sharp Test Ex , 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. We have been using the framework internally for almost a year now, but recently decided to make it public and rebrand it as Fluent Assertions.

Example

// Example
string actual = "ABCDEFGHI";
actual.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

// Example
IEnumerable collection = new[] { 1, 2, 3 };
collection.Should().HaveCount(4, "because we thought we put three items in the collection"))

// Example
var recipe = new RecipeBuilder()
   .With(new IngredientBuilder().For("Milk").WithQuantity(200, Unit.Milliliters))
   .Build();

// Act
Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon);

// Assert
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

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
Last edited Aug 27 at 6:23 AM by dennisdoomen, version 45

 

Want to leave feedback?
Please use Discussions or Reviews instead.

Updating...
© 2006-2010 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2010.8.10.17093