diff --git a/TUnit.Engine/Building/Collectors/AotTestDataCollector.cs b/TUnit.Engine/Building/Collectors/AotTestDataCollector.cs index ddae81e8b6..b6b3944d8c 100644 --- a/TUnit.Engine/Building/Collectors/AotTestDataCollector.cs +++ b/TUnit.Engine/Building/Collectors/AotTestDataCollector.cs @@ -155,15 +155,17 @@ private Task CreateMetadataFromDynamicDiscoveryResult(DynamicDisco private static Attribute[] GetDynamicTestAttributes(DynamicDiscoveryResult result) { + if (result.TestClassType == null) + { + return result.Attributes.ToArray(); + } + // Merge explicitly provided attributes with inherited class/assembly attributes // Order matches GetAllAttributes: method-level first (explicit), then class, then assembly var attributes = new List(result.Attributes); - if (result.TestClassType != null) - { - attributes.AddRange(result.TestClassType.GetCustomAttributes().OfType()); - attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes().OfType()); - } + attributes.AddRange(result.TestClassType.GetCustomAttributes()); + attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes()); return attributes.ToArray(); } diff --git a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs index 2bdf3a6635..f04c6428f2 100644 --- a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs +++ b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs @@ -1932,15 +1932,17 @@ private Task CreateMetadataFromDynamicDiscoveryResult(DynamicDisco private static Attribute[] GetDynamicTestAttributes(DynamicDiscoveryResult result) { + if (result.TestClassType == null) + { + return result.Attributes.ToArray(); + } + // Merge explicitly provided attributes with inherited class/assembly attributes // Order matches GetAllAttributes: method-level first (explicit), then class, then assembly var attributes = new List(result.Attributes); - if (result.TestClassType != null) - { - attributes.AddRange(result.TestClassType.GetCustomAttributes().OfType()); - attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes().OfType()); - } + attributes.AddRange(result.TestClassType.GetCustomAttributes()); + attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes()); return attributes.ToArray(); }