DependsOnFixture
Added in NUnit 5.0.
DependsOnFixtureAttribute specifies that a fixture must run after another
fixture. By default, the referenced fixture must run and pass before the
dependent fixture can run. This can be overridden by setting AllowFailure
to true.
Constructor
DependsOnFixtureAttribute(Type dependencyFixture)
| Parameter |
Type |
Description |
dependencyFixture |
Type |
The fixture that must finish before the current fixture starts. |
Properties
| Property |
Type |
Description |
Default |
AllowFailure |
bool |
Allows the current fixture to run even if the dependency fixture fails. |
false |
Applies To
| Test Methods |
Test Fixtures (Classes) |
Assembly |
| ❌ |
✅ |
❌ |
Example
[TestFixture]
public sealed class DatabaseFixture
{
[Test]
public void CreateSchema()
{
}
}
[TestFixture]
[DependsOnFixture(typeof(DatabaseFixture))]
public sealed class ReportingFixture
{
[Test]
public void GenerateReport()
{
}
}
[TestFixture]
[DependsOnFixture(typeof(DatabaseFixture), AllowFailure = true)]
public sealed class CleanupFixture
{
[Test]
public void RemoveTemporaryFiles()
{
}
}
Notes
- If the dependency fixture fails, the dependent fixture is marked
Skipped by default.
- If
AllowFailure = true, NUnit still runs the dependent fixture even when
the dependency fixture fails.
- Misconfiguration—such as referencing a fixture that is not present in the
current run, creating a circular dependency, using
[Order] anywhere in
the same dependency chain, or configuring fixtures in that dependency chain
for parallel execution—causes the affected fixtures to be marked
Failed as invalid.
See Also