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

Investigate potential false positive for MSTEST0016: Test class should have at least one test method #4543

Open
Youssef1313 opened this issue Jan 7, 2025 · 5 comments
Assignees
Labels

Comments

@Youssef1313
Copy link
Member

Youssef1313 commented Jan 7, 2025

[TestClass]
public class MyTestClass : MyTestClassBase // False positive?
{
    protected override async Task<Something> GetSomething()
    {
        // Customizes behavior for MyTestClass
    }
}

public abstract class MyTestClassBase
{
    protected abstract Task<Something> GetSomething();

    [TestMethod]
    public async Task MyTestMethod()
    {
        var something = await GetSomething();
        // ...
    }
}

AB#2335052

@Evangelink
Copy link
Member

You should not even need the abstract. MyTestMethod is a test method so it should be considered in the scope of MyTestClass.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jan 7, 2025

@Evangelink The test cannot be run in the context of "MyTestClassBase" because GetSomething is intended to be provided by subtypes. We need the method be abstract, hence the class as well. But do you agree it's a false positive?

@Youssef1313
Copy link
Member Author

Hmm, that actually was supposed to be fixed by #2715. I will need to double check again.

@Youssef1313 Youssef1313 self-assigned this Jan 7, 2025
@Evangelink
Copy link
Member

@Youssef1313 Is the issue on base class or sub class?

@Youssef1313
Copy link
Member Author

The diagnostic I got was on the subclass. But note that I haven't checked with exactly the code in the issue. I wrote it directly on GitHub based on an original repro, but the code is structured the same. So I need to check if maybe there is something I'm missing.

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

No branches or pull requests

2 participants