Table of Contents

Class CollectionAttribute

Namespace
Xunit
Assembly
xunit.v3.core.dll

Used to declare a specific test collection for a test class.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class CollectionAttribute : Attribute, ICollectionAttribute
Inheritance
CollectionAttribute
Implements
Inherited Members

Constructors

CollectionAttribute(string)

Initializes a new instance of the CollectionAttribute class, with the given collection name.

public CollectionAttribute(string name)

Parameters

name string

The test collection name.

CollectionAttribute(Type)

Initializes a new instance of the CollectionAttribute class based on a collection definition type, with an auto-generated name based on that type. Equivalent to using CollectionAttribute<TCollectionDefinition>.

public CollectionAttribute(Type type)

Parameters

type Type

The type representing the collection fixture.

Properties

Name

Gets the name of the collection. If CollectionAttribute(string) was called, will return the provided name; if CollectionAttribute(Type) was called, will return a synthetic name for the type.

public string Name { get; }

Property Value

string

Type

Gets the collection definition type. Returns null if the collection is purely based on name.

public Type? Type { get; }

Property Value

Type

Methods

GetCollectionNameForType(Type)

Gets the collection name that will result for a given type.

public static string GetCollectionNameForType(Type type)

Parameters

type Type

The collection type

Returns

string