pengweiqhca / Xunit.DependencyInjection

Use Microsoft.Extensions.DependencyInjection to resolve xUnit test cases.
MIT License
366 stars 49 forks source link

Allow injecting/overriding "RunTestClassesAsync" to control class order execution #129

Closed matan-yadgar closed 2 days ago

matan-yadgar commented 1 week ago

This feature request is not related to an open bug/issue - AFAIK

The feature request description is:

I'd like to control the test class execution order in my test project.

In xUnit - it is implemented by: 1) inheriting "XunitTestCollectionRunner" class and overriding the "protected override async Task RunTestClassesAsync()" function 2) using the implemented runner with TestFrameExecutor and AssemblyRunner 3) setting this framework on an assembly level in the AssemblyInfo.cs file like so: [assembly: TestFramework("Path.To.TestFramework.Namespce", "ProjectName")]

Xunit.DependencyInjection package sets its own test framework.

Adding another TestFramework is invalid.

Hence there is no possibility to control test class execution order inside a collection.

The Xunit.DependencyInjection framework is sealed so it cant be inherited and re-implemented.

I suggest: 1 - honestly - Im not very familiar with this repo so the technical options Im aware of are limited 2 - maybe dont seal the "DependencyInjectionTestFramework"? 3 - allow inhriting the "TestCollectionRunner" in a manner that the new implementation is used instead of the base class 4 - allow somehow overriding the function that sorts the test classes inside a collection

pengweiqhca commented 1 week ago

Whether the custom ITestCollectionOrderer is appropriate or resolve you problem?

matan-yadgar commented 1 week ago

No - the ITestCollectionOrderer sets the order between collections - not the order of classes in the same collection. The only way to set class order is using the XunitTestCollectionRunner as mentioned above

pengweiqhca commented 1 week ago

ITestCaseOrderer?

pengweiqhca commented 2 days ago

See test.