Unit Testing in C#
  • Unit testing in C#
  • Unit testing
    • What to test
    • When to test
    • Qualities of a good unit test suite
    • Qualities of a good unit test
    • Dealing with dependencies
    • Running the tests
  • NUnit
    • Quick glance at NUnit
    • Creating a NUnit test project
    • Anatomy of a test fixture
    • Lifecycle of a test fixture
    • Assertions
    • Asynchronous executions
    • Parameterized tests
    • Assumptions
    • Describing your tests
  • Moq
    • Quick glance at Moq
    • Method arguments
    • Method calls
    • Properties
    • Results
    • Callbacks
    • Exceptions
    • Events
    • Verifications
    • Base class
    • Mock customization
    • Implicit mocks
    • Mock repository
    • Custom matchers
    • Multiple interfaces
    • Protected members
    • Generic methods
    • Delegates
  • AutoFixture
    • Quick glance at AutoFixture
    • Fixture
    • Create and Build
    • Type customization
    • Data annotations
    • Default configurations
    • Building custom types
    • Relays
    • Tricks
    • Idioms
    • Integration with NUnit
    • Integration with Moq
    • Combining AutoFixture with NUnit and Moq
    • Extending AutoFixture
  • Advanced topics
    • Testing HttpClient
Powered by GitBook
On this page
  • The IFixture interface
  • Properties of IFixture
  • Methods of IFixture
  • The ISpecimenBuilder interface
  • Extension methods
  1. AutoFixture

Fixture

PreviousQuick glance at AutoFixtureNextCreate and Build

Last updated 4 years ago

Despite its complex architecture, AutoFixture exposes a very simple programming interface wrapped by the Fixture type.

A Fixture uses a graph of ISpecimenBuilders to serve requests to create auto-generated values (also known as Specimens or ).

Developers can use its parameterless constructor to obtain an instance based on the default configuration. This configuration includes the wiring for the different parts of the framework and configurations for the most common types of the .

The IFixture interface

Fixture implements the IFixture interface. The properties and methods of this interface are used to configure the specimens generation and the creation of the specimens via AutoFixture's fluent API.

Properties of IFixture

IFixture exposes the following properties

  • Behaviors: a list of decorators whose execution wraps the execution of each builder

  • Customizations: a list of customizations that are used to create values before using default builders

  • ResidueCollectors: a collection of builders to be used as fallback in case no default builder nor customization was able to serve the request

  • OmitAutoProperties: specifies whether properties should receive a value, default is false.

  • RepeatCount: specifies the amount of items to be added when creating a collection, default is 3.

Methods of IFixture

  • Build<T>(): initiates the creation of an instance of the given type ignoring all prior customizations

  • Customize<T>(): customizes the creation algorithm for all instances of a given type

  • Customize(): applies a customization to the current Fixture

The ISpecimenBuilder interface

Extension methods

On top of the methods above, several extension methods are defined on the IFixture type. These extension methods are all built on the basic operations exposed by IFixture. The most important ones will be presented in depth later on.

On top of IFixture, Fixture implements the ISpecimenBuilder interface. This interface exposes the Create method that is used by more user-friendly versions of this method. More information about the and the will follow.

Anonymous Variables
Base Class Library
specimen builders
Create method
Here you can have a glance at the internal architecture of AutoFixture