Skip to content

Commit 21f697d

Browse files
Fix attribute property injection timing issue
Test attributes like MyDataProvider were being initialized before their properties were injected, causing 'Expected InnerClass to not be null' errors in dependency injection scenarios. Added property injection for test attributes before initialization to ensure data source generators have their dependencies ready. Co-authored-by: Tom Longhurst <thomhurst@users.noreply.github.com>
1 parent 816da19 commit 21f697d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

TUnit.Engine/Services/SingleTestExecutor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ await PropertyInjectionService.InjectPropertiesAsync(
138138
// Note: Property-injected values are already tracked within PropertyInjectionService
139139
// No need to track them again here
140140

141+
// Inject properties into test attributes before they are initialized
142+
// This ensures that data source generators and other attributes have their dependencies ready
143+
await PropertyInjectionService.InjectPropertiesIntoArgumentsAsync(
144+
test.Context.TestDetails.Attributes.ToArray(),
145+
test.Context.ObjectBag,
146+
test.Context.TestDetails.MethodMetadata,
147+
test.Context.Events).ConfigureAwait(false);
148+
141149
await _eventReceiverOrchestrator.InitializeAllEligibleObjectsAsync(test.Context, cancellationToken).ConfigureAwait(false);
142150

143151
PopulateTestContextDependencies(test);

0 commit comments

Comments
 (0)