diff --git a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs index 1a1aabfdcd..ab4e305060 100644 --- a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs +++ b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs @@ -503,7 +503,7 @@ private static async IAsyncEnumerable DiscoverTestsInAssemblyStrea continue; } - MethodInfo[] testMethods; + IEnumerable testMethods; try { // Check if this class inherits tests from base classes @@ -513,15 +513,14 @@ private static async IAsyncEnumerable DiscoverTestsInAssemblyStrea { // Get all test methods including inherited ones testMethods = GetAllTestMethods(type) - .Where(static m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract) - .ToArray(); + .Where(static m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract); } else { // Only get declared test methods - testMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly) - .Where(static m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract) - .ToArray(); + testMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | + BindingFlags.DeclaredOnly) + .Where(static m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract); } } catch (Exception) diff --git a/TUnit.Engine/Services/TestRegistry.cs b/TUnit.Engine/Services/TestRegistry.cs index cc76b93a1d..4e75f2d07b 100644 --- a/TUnit.Engine/Services/TestRegistry.cs +++ b/TUnit.Engine/Services/TestRegistry.cs @@ -261,7 +261,9 @@ private async Task CreateMetadataFromDynamicDiscoveryResult(Dynami TestName = testName, TestClassType = result.TestClassType, TestMethodName = methodInfo.Name, - Dependencies = GetDependenciesOptimized(result.Attributes), + Dependencies = result.Attributes.OfType() + .Select(x => x.ToTestDependency()) + .ToArray(), DataSources = [], ClassDataSources = [], PropertyDataSources = [], @@ -339,25 +341,6 @@ private sealed class PendingDynamicTest public required Type TestClassType { get; init; } } - - /// - /// Optimized method to get dependencies without LINQ allocations - /// - private static TestDependency[] GetDependenciesOptimized(ICollection attributes) - { - var dependencies = new List(attributes.Count); - foreach (var attr in attributes) - { - if (attr is DependsOnAttribute dependsOn) - { - dependencies.Add(dependsOn.ToTestDependency()); - } - } - return dependencies.ToArray(); - } - - - /// /// Optimized method to convert attributes to array without LINQ allocations ///