Table of Contents

Class TestFixtureSourceAttribute

Namespace
NUnit.Framework
Assembly
nunit.framework.dll

Identifies the source used to provide test fixture instances for a test class.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class TestFixtureSourceAttribute : NUnitAttribute, IFixtureBuilder2, IFixtureBuilder
Inheritance
TestFixtureSourceAttribute
Implements
Inherited Members

Constructors

TestFixtureSourceAttribute(string)

Construct with the name of the method, property or field that will provide data

public TestFixtureSourceAttribute(string sourceName)

Parameters

sourceName string

The name of a static method, property or field that will provide data.

TestFixtureSourceAttribute(Type)

Construct with a Type

public TestFixtureSourceAttribute(Type sourceType)

Parameters

sourceType Type

The type that will provide data

TestFixtureSourceAttribute(Type, string)

Construct with a Type and name

public TestFixtureSourceAttribute(Type sourceType, string sourceName)

Parameters

sourceType Type

The Type that will provide data

sourceName string

The name of a static method, property or field that will provide data.

Fields

MUST_BE_STATIC

Error message string is public so the tests can use it

public const string MUST_BE_STATIC = "The sourceName specified on a TestCaseSourceAttribute must refer to a static field, property or method."

Field Value

string

Properties

Category

Gets or sets the category associated with every fixture created from this attribute. May be a single category or a comma-separated list.

public string? Category { get; set; }

Property Value

string

SourceName

The name of a the method, property or field to be used as a source

public string? SourceName { get; }

Property Value

string

SourceType

A Type to be used as a source

public Type? SourceType { get; }

Property Value

Type

Methods

BuildFrom(ITypeInfo)

Builds any number of test fixtures from the specified type.

public IEnumerable<TestSuite> BuildFrom(ITypeInfo typeInfo)

Parameters

typeInfo ITypeInfo

The TypeInfo for which fixtures are to be constructed.

Returns

IEnumerable<TestSuite>

BuildFrom(ITypeInfo, IPreFilter)

Builds any number of test fixtures from the specified type.

public IEnumerable<TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter)

Parameters

typeInfo ITypeInfo

The TypeInfo for which fixtures are to be constructed.

filter IPreFilter

PreFilter used to select methods as tests.

Returns

IEnumerable<TestSuite>

GetParametersFor(Type)

Returns a set of ITestFixtureData items for use as arguments to a parameterized test fixture.

public IEnumerable<ITestFixtureData> GetParametersFor(Type sourceType)

Parameters

sourceType Type

The type for which data is needed.

Returns

IEnumerable<ITestFixtureData>