Posted by johnsmart
on January 4, 2014 at 7:42 AM PST
An essential part of a well-written unit test is a well-written assertion. The assertion states the behavior you expect out of the system. It should tell you at a glance what a test is trying to demonstrate. It should be simple and obvious. You should not have to decipher conditional logic or sift through for loops to understand what it is doing. In addition, any non-trivial logic in a test case increases the risk of the test itself being wrong.
Over recent years there has been a rise in the popularity of tools and techniques that make it easier to write more fluent code, both for production code and for tests. In the testing space in particular, there are many libraries that now support fluent assertions in different languages. Fluent assertions are simply ways of writing assertions in a more natural, more readable and more expressive manner.
There are two main flavors to fluent assertions. The first typically uses the word