Class AssemblySetupAttribute
- Namespace
- TinyBDD
- Assembly
- TinyBDD.dll
Marks a type as an assembly-wide fixture that should be initialized before any tests run.
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public sealed class AssemblySetupAttribute : Attribute
- Inheritance
-
AssemblySetupAttribute
- Inherited Members
Examples
Example: Register a database fixture
using TinyBDD;
[assembly: AssemblySetup(typeof(DatabaseFixture))]
public class DatabaseFixture : AssemblyFixture
{
private TestDatabase? _db;
public TestDatabase Database => _db!;
protected override async Task SetupAsync(CancellationToken ct)
{
_db = new TestDatabase();
await _db.StartAsync(ct);
}
protected override async Task TeardownAsync(CancellationToken ct)
{
if (_db is not null)
await _db.DisposeAsync();
}
}
Example: Register multiple fixtures
[assembly: AssemblySetup(typeof(DatabaseFixture))]
[assembly: AssemblySetup(typeof(WebServerFixture))]
[assembly: AssemblySetup(typeof(MessageQueueFixture))]
Remarks
Apply this attribute at the assembly level to register one or more AssemblyFixture types that will be instantiated and initialized before any tests execute, and torn down after all tests complete.
Multiple fixtures can be registered by applying this attribute multiple times. Fixtures are executed in the order they are registered.
This is a framework-agnostic mechanism that works with xUnit, NUnit, and MSTest.
Constructors
AssemblySetupAttribute(Type)
Initializes a new instance of the AssemblySetupAttribute class.
public AssemblySetupAttribute(Type fixtureType)
Parameters
fixtureTypeTypeThe type of the assembly fixture. Must derive from AssemblyFixture.
Exceptions
- ArgumentNullException
Thrown if
fixtureTypeis null.- ArgumentException
Thrown if
fixtureTypedoes not derive from AssemblyFixture.
Properties
FixtureType
Gets the type of the assembly fixture to initialize.
public Type FixtureType { get; }