Skip to content

Test Explorer - Give frameworks full control over test explorer layout #3371

@thomhurst

Description

@thomhurst

I assume that the test explorer view in IDEs is driven by the TestMethodIdentifierProperty on TestNodes?

This provides no way to show parameter types or argument types.

In data driven testing, I'd say it's not uncommon to inject in different objects that inherit from a base, and then want to run only those particular tests. This doesn't seem to be possible currently.

For example, consider a multi-tenanted application, and you want to run tests against a particular tenant you'd made changes for.

In pseudo code, the test is set up like this:

class TenantBase { ... }
class Tenant1 : TenantBase { ... }
class Tenant2 : TenantBase { ... }
class Tenant3 : TenantBase { ... }

[Inject<Tenant1>]
[Inject<Tenant2>]
[Inject<Tenant3>]
class MyTestClass(TenantBase tenant)

Meaning it is repeated for each tenant, with a different object being passed in.

Because the test explorer / test node properties have no visibility of the parameter types, or more importantly, the argument types, there is no way for it to display this in a nice way.

For example, in VSTest in NUnit, I could set up a test like this, and I'd get in the test explorer:

> MyTestClass
    > MyTestClass(MyNamespace.Tenant1)
    > MyTestClass(MyNamespace.Tenant2)
    > MyTestClass(MyNamespace.Tenant3)

This makes it super easy to selectively run the tests that I want.


I have tried this in my own framework.
Code

new TestMethodIdentifierProperty
(
...
TypeName: testDetails.ClassType.Name,
...
)
[ClassDataSource(typeof(Derived1))]
[ClassDataSource(typeof(Derived2))]
public class ClassDataSourceDrivenTests2
{
    private readonly Base _base;

    public ClassDataSourceDrivenTests2(Base @base)
    {
        _base = @base;
    }
    
    [Test]
    public void Base_Derived1()
    {
        // Dummy method
    }

    [Test]
    public void Base_Derived2()
    {
        // Dummy method
    }

    public class Base {}
    public class Derived1 : Base {}
    public class Derived2 : Base {}
}

Text explorer view:
image

So you can see that it makes it very difficult - I don't actually know which one I'm running.

Also, this would technically affect the test methods too - While they have the parameter types, there's no way to pass in the argument types, so we wouldn't be able to differentiate. Of course, we can mitigate this with a custom display name, but this isn't something we can do for the class itself.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions