Skip to content

Cannot add more than one dynamically created test for specific method #4052

@damiand2

Description

@damiand2

Hi, i followed documentation https://tunit.dev/docs/experimental/dynamic-tests and wanted to add several tests for single method, example:
`
public class SynchronizationTests
{

[DynamicTestBuilder]
public static void BuildSmokeTests(DynamicTestBuilderContext context)
{
    foreach (var type in typeof(SomeType<,,>).Assembly.GetExportedTypes())
    {
        if (type.IsClass == false || type.IsAbstract == true)
            continue;
        
        context.AddTest(new DynamicTest<SynchronizationTests>
        {
            TestMethod = @class => @class.parametrized_smoke_tests(DynamicTestHelper.Argument<Type>()),
            TestMethodArguments = [type]                
        });                
    }            
}


public async Task parametrized_smoke_tests(Type commandType)
{
	//real test
}

}

`
In debugging i see that context.AddTest is invoked mutlitple times (correct), however parametrized_smoke_tests is only called once - with data passed to first call to context.AddTest.

Additionally - it would be nice to provide custom test names (similiar to TestCaseData.SetName https://docs.nunit.org/articles/nunit/writing-tests/TestCaseData.html) to show more meaningful test names in test explorer or console.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions