Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCategory on class doesn't apply to inherited test methods #498

Closed
spanglerco opened this issue Oct 11, 2018 · 1 comment
Closed

TestCategory on class doesn't apply to inherited test methods #498

spanglerco opened this issue Oct 11, 2018 · 1 comment
Labels
Help-Wanted The issue is up-for-grabs, and can be claimed by commenting

Comments

@spanglerco
Copy link
Contributor

Description

I have a test class that inherits test methods from a base test class, but I want to apply a TestCategory from the derived class in order to filter tests to run. The current implementation only looks at the TestCategory starting at the class that declares the test method, rather than the class being enumerated. But since TestCategory is inherited, I think it would make sense for it to include all categories starting at the class being enumerated.

I have a working implementation of this in a fork and am opening this issue to determine if the change is desired or if it's working as intended.

There's also a question about how assembly-level TestCategory attributes should work in this case. The code currently only considers the assembly containing the test method and not the assemblies containing the test class hierarchy. My fork changes it to only consider the assembly containing the test class being enumerated.

Steps to reproduce

[TestClass]
[TestCategory("base")]
public abstract class Base
{
    [TestMethod]
    public void TestSomeBaseInterfaceMethod() {}
}

[TestClass]
[TestCategory("derived")]
public class Derived : Base {}

Expected behavior

Derived.TestSomeBaseInterfaceMethod has both base and derived test categories:
image

Actual behavior

Derived.TestSomeBaseInterfaceMethod only has the base test category:
image

Environment

MSTest 1.3.2

@karanjitsingh karanjitsingh added enhancement Help-Wanted The issue is up-for-grabs, and can be claimed by commenting and removed Discussion labels Nov 6, 2018
@karanjitsingh
Copy link
Contributor

karanjitsingh commented Nov 6, 2018

Hey @spanglerco, thanks for pointing this out. Marking this as an enhancement and is up for grabs for a contribution.

Just adding to the expected behavior a little, TestCategory should not override but add another category to the class. A test class can take multiple test categories, so for derived classes defining TestCategory should also show up when filtering for their base class category

[TestClass]
[TestCategory("base")]
public abstract class Base
{
    [TestMethod]
    public void TestSomeBaseInterfaceMethod() {}
}

// With test category
[TestClass]
[TestCategory("derived")]
public class Derived : Base {}

// Without test category
[TestClass]
public class Derived2 : Base {}

Using the filter "base" should run both Derived and Derived2 classes whereas using filter "derived" should only run Derived class.

Will be happy to take contribution with appropriate tests and expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help-Wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

No branches or pull requests

4 participants