diff --git a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs index ff515d62e6..6cb4b98438 100644 --- a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs @@ -2478,6 +2478,7 @@ private static void GenerateReturnHandling( private static void GenerateDependencies(CodeWriter writer, Compilation compilation, IMethodSymbol methodSymbol) { var dependsOnAttributes = methodSymbol.GetAttributes() + .Concat(methodSymbol.ContainingType.GetAttributes()) .Where(attr => attr.AttributeClass?.Name == "DependsOnAttribute" && attr.AttributeClass.ContainingNamespace?.ToDisplayString() == "TUnit.Core") .ToList(); diff --git a/TUnit.TestProject/DependsOnTests.cs b/TUnit.TestProject/DependsOnTests.cs index 7600ac9854..359ef05e4d 100644 --- a/TUnit.TestProject/DependsOnTests.cs +++ b/TUnit.TestProject/DependsOnTests.cs @@ -28,3 +28,31 @@ public static async Task AssertStartTimes() await Assert.That(_test2Start).IsAfterOrEqualTo(_test1Start.AddSeconds(4.9)); } } + +public sealed class MyAsyncTest +{ + public static int NumberOfInvocations = 0; + + [Test] + public async Task Test() + { + NumberOfInvocations += 1; + await Assert.That(NumberOfInvocations).IsEqualTo(1); + } +} + +[EngineTest(ExpectedResult.Pass)] +[DependsOn(typeof(MyAsyncTest), nameof(Test))] +public sealed class DependsOn_AsyncTest +{ + [Test] + public async Task Test() => await Assert.That(MyAsyncTest.NumberOfInvocations).IsEqualTo(1); +} + +[EngineTest(ExpectedResult.Pass)] +[DependsOn(typeof(MyAsyncTest), nameof(Test))] +public sealed class DependsOn_AsyncTest_Two +{ + [Test] + public async Task Test() => await Assert.That(MyAsyncTest.NumberOfInvocations).IsEqualTo(1); +}