Skip to content

Welcome to the NFluent wiki

Cyrille DUPUYDAUBY edited this page Feb 2, 2018 · 6 revisions

What is NFluent?

NFluent is an assertion library. It helps developers write and maintain their automated unit tests.

What are the prerequisites?

  • Understanding unit testing/TDD/BDD (you can try NUnit website if you want to know more on those topics)
  • Simply add NFluent to your test project(s) with Nuget (search for NFluent)
  • Nothing else. NFluent is compatible with all testing frameworks (NUnit, xUnit, MSTest,...)

Writing your first test.

It is that simple:

using NFluent;
...
// [Fact] with xUnit 
// [TestMethod] with MsTest
[Test] // Using NUnit
public void CalculatorShouldAddCorrectly()
{
  var myCalculator = new Calculator();
  // this lines verifies that the Add method returns the expected
  // result when adding 2 and 5.
  Check.That(myCalculator.Add(2, 5) ).IsEqualTo(7);
  // NUnit equivalent Assert.AreEqual(7, myCalculator.Add(2,5)
}

Why using NFluent instead of the assertion methods provided by your unit test framework?

  1. Clearly expressed checks: NFluent assertions can be read (almost) as a sentence. Previous example is: check that mycalculator(2, 5) result is equal to 7. This is way better than: assert that are equal 7 and mycalculator(2, 5) result, unless you are Yoda and you prefer your verb in front
  2. Helpful error messages: NFluent provides explicit and guiding messages when an assertion fails. Specifically, it provides a sentence explaining precisely why the test failed as well as information regarding the observed result as well as the expected one.
  3. Auto-completion driven: modern IDEs provide performant autocompletion logic. NFluent leverages those so you do not have to browse the documention to discover what you can do.
  4. Decoupling: using an assertion framework will reduce the amount of effort needed if you want/have to migrate to another testing framewok.
Clone this wiki locally