Facts & Fixtures

xUnit.js borrows the concepts of Facts from xUnit.net, to remind developers to only test a single behavioral promise at a time. Consequently, facts should be named after the promise of behavior that they exercise, without a prefix or suffix of "test", e.g.: function ComparesTrueAndNotFalse(){ // Arrange var expected=true; // Act var actual=!false; //Assert Assert.Equal(expected,actual); }

Facts are organized and grouped in Fixtures, to encapsulate tests for common behaviors or APIs. Fixtures are xUnit.js.Model.IRunnable containers that execute all of their registered Fixtures and Facts recursively when run. A common organization of nested Fixtures is:

e.g.:

xUnit.js is designed to facilitate common testing patterns, such as Arrange-Act-Assert, Single-Assert, and Promise-Naming. While it is not necessary to follow these patterns, it is highly encouraged, as they facilitate test comprehension and maintenance by standardizing the shape of the facts being tested.

It is also encouraged to standardize three variables: expected, target, and actual, and to exclude as much logic as possible from the Act and Assert steps. In this way, the test can be read most efficiently backwards, Assert-Act-Arrange, and the shape of the test becomes intuitively clear before any higher-order comprehension is required to grok the logic in the setup.