Skip to content

[BUG] Test Classes With Injected Dependencies Cause Matrix Expansion To Fail #4836

@Xen0byte

Description

@Xen0byte

Description

After creating a matrix test in a class with injected dependencies, it was observed that matrix expansion fails.

Expected Behavior

Matrix expansion should work regardless of the test class constructor signature.

Actual Behavior

The permutations are not discovered, and running the test results in a failure.

Steps to Reproduce

  1. create a test class with injected dependencies
  2. create a matrix test
  3. compile and observe that the permutations are not discovered
  4. run and observe the failure

TUnit Version

1.13.51

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Visual Studio

  Message: 
Failed to expand data source for test 'Test': Index was outside the bounds of the array.

  Stack Trace: 
FailedExecutableTest.CreateInstanceAsync()
TestCoordinator.ExecuteTestLifecycleAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
<<ExecuteWithTimeoutAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
TimeoutHelper.ExecuteWithTimeoutAsync[T](Func`2 taskFactory, Nullable`1 timeout, CancellationToken cancellationToken, String timeoutMessage)
TimeoutHelper.ExecuteWithTimeoutAsync(Func`2 taskFactory, Nullable`1 timeout, CancellationToken cancellationToken, String timeoutMessage)
<<ExecuteTestInternalAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
TestCoordinator.ExecuteTestInternalAsync(AbstractExecutableTest test, CancellationToken cancellationToken)

PowerShell

failed Get_By_ID_With_Existing_Event_Returns_Event (0ms)
  TUnit.Engine.Exceptions.TestFailedException: InvalidOperationException: Failed to expand data source for test 'Get_By_ID_With_Existing_Event_Returns_Event': Index was outside the bounds of the array.
  --->  System.IndexOutOfRangeException: Index was outside the bounds of the array.
    at TUnit.Generated.Path_To_Get_By_ID_With_Existing_Event_Returns_Event__EventStateDto_TimingTypeDto_bool_TestSource.<>c.<GetTestsAsync>b__0_1(Type[] typeArgs, Object[] args) in path\to\Events.Tests.Integration\obj\Debug\net10.0\TUnit.Core.SourceGenerator\TUnit.Core.SourceGenerator.Generators.TestMetadataGenerator\Path_To_Get_By_ID_With_Existing_Event_Returns_Event__EventStateDto_TimingTypeDto_bool.g.cs:108
    at TUnit.Core.TestMetadata`1.<>c__DisplayClass5_0.<set_InstanceFactory>b__0(Type[] typeArgs, Object[] args)
    at TUnit.Engine.Building.TestBuilder.BuildTestsFromMetadataAsync(TestMetadata metadata, TestBuildingContext buildingContext)

Additional Context

Not sure if it matters, but dependency injection is managed via [ClassConstructorAttribute<T>].

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions