MSTEST0057 false positive when attribute has static field with initializer
MSTEST0057 reports a false positive when the attribute has a static field or property with an initializer. Not happens for const
public class DerivedTestMethodAttribute : TestMethodAttribute
{
private static string Text { get; } = "I'm static property";
private static readonly string _text = "I'm static field";
public DerivedTestMethodAttribute([CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
: base(callerFilePath, callerLineNumber)
{
}
}
MSTEST0057: TestMethodAttribute derived class 'AftTestMethodAttribute' should add CallerFilePath and CallerLineNumber parameters to its constructor
BTW, the documentation is missing for this diagnostic.
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):
- https://github.com/microsoft/testfx/issues/6935
Yes, that's probably a duplicate. When a class has a static field with an initializer, the compiler generates a static constructor.
I'd add these test cases to the analyzer anyway.
Hello,
This has been fixed and will be released in MSTest 4.1 https://github.com/microsoft/testfx/pull/6937