AssemblyFixtureProviderAttribute Class

Definition

Indicates that the methods on the specified FixtureType annotated with AssemblyInitializeAttribute or AssemblyCleanupAttribute should be discovered and executed once per consuming test assembly, even when the methods are not declared in that test assembly itself.

[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)]
public sealed class AssemblyFixtureProviderAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class AssemblyFixtureProviderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)>]
type AssemblyFixtureProviderAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)>]
[<System.Runtime.CompilerServices.Nullable(0)>]
type AssemblyFixtureProviderAttribute = class
    inherit Attribute
Public NotInheritable Class AssemblyFixtureProviderAttribute
Inherits Attribute
Inheritance
AssemblyFixtureProviderAttribute
Attributes

Examples

// In Contoso.TestInfra.dll
[assembly: AssemblyFixtureProvider(typeof(GlobalFixtures))]

public static class GlobalFixtures
{
    [AssemblyInitialize]
    public static void Init(TestContext context) { /* ... */ }

    [AssemblyCleanup]
    public static void Cleanup() { /* ... */ }
}

Remarks

Apply this attribute at the assembly level on the library that exposes the shared fixture. Every test assembly that ends up loading the library at runtime will then pick up its AssemblyInitializeAttribute / AssemblyCleanupAttribute methods without the test project needing to declare anything itself.

If the consuming test assembly already declares its own AssemblyInitializeAttribute or AssemblyCleanupAttribute method, the local declaration always wins; methods contributed via AssemblyFixtureProviderAttribute only fill empty slots.

The attribute can be applied multiple times on the same assembly to expose more than one fixture type. The attribute can also be applied on the consuming test assembly itself to opt into fixtures defined in a third-party library that cannot be modified.

Constructors

Name Description
AssemblyFixtureProviderAttribute(Type)

Initializes a new instance of the AssemblyFixtureProviderAttribute class.

Properties

Name Description
FixtureType

Gets the type whose AssemblyInitializeAttribute and AssemblyCleanupAttribute methods are exposed.

Applies to