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

Private static field causes false positive for analyzer rule MSTEST0005 #4590

Open
abatishchev opened this issue Jan 9, 2025 · 0 comments
Open

Comments

@abatishchev
Copy link

Describe the bug

A private static field of type TestContext causes a false positive for rule MSTEST0005:

Property 'TestContext' should be valid

Steps To Reproduce

The following code:

[TestClass]
public class MiseCorrelationIdProviderTests
{
    private static TestContext _context;

    [ClassInitialize]
    public static void ClassInitialize(TestContext context) =>
        _context = context;
}    

causes the following warning:

Image

Expected behavior

A field does not trigger a rule for a property.

Actual behavior

It does.

Additional context

<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.7.0" />
<PackageVersion Include="MSTest.TestFramework" Version="3.7.0" />
<GlobalPackageReference Include="MSTest.Analyzers" Version="3.7.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants