Skip to content

[Bug]: dynamic tests do not honor test class attributes #4186

@damiand2

Description

@damiand2

Description

dynamic test generation does not honor base class NotInParalel and all dynamically generated tests run in paralel
sample pseudo code:
`
[NotInParalel]
public class BaseTest
{}

public class Tests : BaseTest
{
[DynamicTestBuilder]
public static void getDynamicTests(DynamicTestBuilderContext context)
{
foreach (var type in typeof(xxx).Assembly.GetExportedTypes())
{
if (type.IsClass == false || type.IsAbstract == true)
continue;

     context.AddTest(new DynamicTest<Tests>
     {
         TestMethod = @class => @class.TestMethod(DynamicTestHelper.Argument<Type>()),
         TestMethodArguments = [type],
         DisplayName = $"dynamic test for {type.Name}",
         //Attributes = [new NotInParallelAttribute()]
     });                
	}
}

public async TestMethod(Tyoe)
{}
}
`

With attributes commented out - tests run in paralel, ignoring base class attribute, only manually repeating attributes from base class ends in expected behaviour

Expected Behavior

class attributes should be honored

Actual Behavior

class attributes are ignored

Steps to Reproduce

as above

TUnit Version

1.7.0

.NET Version

10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

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