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

MSTEST0002: False positive, generic test class is valid #2419

Closed
Evangelink opened this issue Feb 22, 2024 · 0 comments · Fixed by #2428
Closed

MSTEST0002: False positive, generic test class is valid #2419

Evangelink opened this issue Feb 22, 2024 · 0 comments · Fixed by #2428
Assignees
Milestone

Comments

@Evangelink
Copy link
Member

Evangelink commented Feb 22, 2024

Describe the bug

Rule MSTEST0002 always raises an issue on generic classes but this is leading to false positives. It's perfectly valid to have a generic test class that serves as base class to other classes.

The generic class itself cannot be run which could be flagged by a different analyzer (see #2051 (comment)).

Steps To Reproduce

[TestClass]
public /*abstract*/ class C<T>
{
    [ClassInitialize(InheritanceBehavior.BeforeEachDerivedClass)]
    public static void CI(TestContext testContext) 
    {
    }

    [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass)]
    public static void CC()
    {
    }

    [TestInitialize]
    public void TI()
    {
    }

    [TestCleanup]
    public void TC()
    {
    }

    [TestMethod]
    public void C1() // This won't be called from C<> but this would work through A
    {
    }
}

[TestClass]
public class A : C<int>
{
    [TestMethod]
    public void A1()
    {
    }

    [TestInitialize]
    public void ATI()
    {
    }

    [TestCleanup]
    public void ATC()
    {
    }
}

AB#1976480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant