Skip to content

MSTEST0057 triggers on static constructors #6935

@jnyrup

Description

@jnyrup

Describe the bug

When a class deriving from TestMethodAttribute has a static constructor, MSTEST0057 is triggered suggesting adding [CallerFilePath] and [CallerLineNumber], despite the class already having the suggested constructor.

Steps To Reproduce

In this case the fixer suggest adding a constructor identical to the existing constructor.

public class MyTestMethodAttribute : TestMethodAttribute // <-- MSTEST0057 is triggered
{
    static DateTimeOffset s_field = new();

    public MyTestMethodAttribute([CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
        : base(callerFilePath, callerLineNumber)
    {
    }
}

This this case the fixer suggests adding [CallerFilePath] and [CallerLineNumber] to the static constructor.

public class SomeTestMethodAttribute : TestMethodAttribute
{
    static SomeTestMethodAttribute() // <-- MSTEST0057 is triggered
    {
    }

    public SomeTestMethodAttribute([CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
        : base(callerFilePath, callerLineNumber)
    {
    }
}

Expected behavior

MSTEST0057 should not be triggered.

Actual behavior

MSTEST0057 is triggered.

Additional context

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions