Last Updated: February 25, 2016
·
1.687K
· edmondo1984

Better tests in .NET through Fluent Assertions

I have recently discovered a library for .NET which has improved the way I write my tests for .NET. It works with all major testing frameworks and has two clear benefits:

  • It makes your tests much more readable
  • It provides clear error messages so you have to limit your debugging activity

This library is called FluentAssertions and is available on NuGet and CodePlex: http://fluentassertions.codeplex.com/

Examples from CodePlex

Simple example

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

A useful error message

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);

Awesome!

1 Response
Add your response

Thanks for the positive note. We're doing our best to make it the best assertion framework in the .NET realm. It might be interesting to learn why I created Fluent Assertions in the first place at http://www.dennisdoomen.net/2011/07/why-i-created-fluent-assertions-in.html

over 1 year ago ·