SpecsFor overview

SpecsFor is a library designed to make crafting tests for .NET code a breeze. It includes a base test fixture that automatically handles common testing concerns, packages to address common testing needs (such as mocking and fluent asserts), and helpers to easily overcome many testing hurdles.

SpecsFor is built on top of five excellent open-source libraries, each of which solves various testing challenges.

NUnit

At its core, SpecsFor utilizes the NUnit Testing Framework. NUnit is a mature library for creating automated tests using .NET. Most build servers and productivity tools support it, and since SpecsFor is built on top of NUnit, that means most build servers and productivity tools also support SpecsFor.

Moq

SpecsFor includes the Moq mocking framework. Mocking plays an important role in top-down development and test-driven development, and Moq allows you to easily configure mocks and verify interactions with them.

StructureMap

SpecsFor uses StructureMap's auto-mocking container to create your System Under Test (SUT) for you automatically. If your SUT requires any dependencies, StructureMap will create them for you, supplying mock objects if possible.

Should

Out of the box, NUnit provides assertions that read more like machine instructions rather than natural language. Should provides assertions in the form of extension methods for most of the common things you might want to assert.

ExpectedObjects

Finally, SpecsFor includes the ExpectedObjects library. By default in .NET, two references are only equal if they point to the exact same instance of a class. You can change this behavior by overriding the base Object.Equals method, but doing this across all the objects you may want to compare is non-trivial. ExpectedObjects overcomes this problem by allowing you to assert that two instances look like one another.

The Special Sauce

SpecsFor is the special sauce that brings all these packages together into a unified, easy-to-use platform. SpecsFor provides a base class, SpecsFor, that automatically creates your System Under Test using StructureMap, automatically creates mocks using Moq and provides an easy way to retrieve them later, and provides numerous ways to write clean specs, including a Convention System, context classes, and numerous additional helpers to make you more productive.


Did this page help you?