Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TUnit.Engine/Building/Collectors/AotTestDataCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private Task<TestMetadata> CreateMetadataFromDynamicDiscoveryResult(DynamicDisco
TestName = testName,
TestClassType = result.TestClassType,
TestMethodName = methodInfo.Name,
Dependencies = result.Attributes.OfType<DependsOnAttribute>().Select(a => a.ToTestDependency()).ToArray(),
Dependencies = AttributeHelpers.ExtractDependencies(result.Attributes),
DataSources = [], // Dynamic tests don't use data sources in the same way
ClassDataSources = [],
PropertyDataSources = [],
Expand Down
3 changes: 2 additions & 1 deletion TUnit.Engine/Discovery/ReflectionTestDataCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ private Task<TestMetadata> CreateMetadataFromDynamicDiscoveryResult(DynamicDisco
TestName = testName,
TestClassType = result.TestClassType,
TestMethodName = methodInfo.Name,
Dependencies = result.Attributes.OfType<DependsOnAttribute>().Select(static a => a.ToTestDependency()).ToArray(),
Dependencies = AttributeHelpers.ExtractDependencies(result.Attributes),
DataSources = [], // Dynamic tests don't use data sources in the same way
ClassDataSources = [],
PropertyDataSources = [],
Expand All @@ -2248,6 +2248,7 @@ private Task<TestMetadata> CreateMetadataFromDynamicDiscoveryResult(DynamicDisco
return Task.FromResult<TestMetadata>(metadata);
}


private static Attribute[] GetDynamicTestAttributes(DynamicDiscoveryResult result)
{
if (result.TestClassType == null)
Expand Down
29 changes: 29 additions & 0 deletions TUnit.Engine/Helpers/AttributeHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using TUnit.Core;

namespace TUnit.Engine.Helpers;

/// <summary>
/// Shared attribute-extraction helpers used by the dynamic-discovery code paths
/// (AOT, reflection, and runtime registration) so they stay in sync.
/// </summary>
internal static class AttributeHelpers
{
/// <summary>
/// Extracts <see cref="TestDependency"/> entries from a materialised attribute list.
/// Returns the shared empty array when no <see cref="DependsOnAttribute"/> is present.
/// </summary>
public static TestDependency[] ExtractDependencies(List<Attribute> attributes)
{
List<TestDependency>? dependencies = null;

foreach (var attribute in attributes)
{
if (attribute is DependsOnAttribute dependsOn)
{
(dependencies ??= []).Add(dependsOn.ToTestDependency());
}
}

return dependencies?.ToArray() ?? [];
}
}
4 changes: 1 addition & 3 deletions TUnit.Engine/Services/TestRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ private TestMetadata CreateMetadataFromDynamicDiscoveryResult(DynamicDiscoveryRe
TestName = methodInfo.Name,
TestClassType = result.TestClassType,
TestMethodName = methodInfo.Name,
Dependencies = result.Attributes.OfType<DependsOnAttribute>()
.Select(x => x.ToTestDependency())
.ToArray(),
Dependencies = AttributeHelpers.ExtractDependencies(result.Attributes),
DataSources = [],
ClassDataSources = [],
PropertyDataSources = [],
Expand Down
Loading