Skip to content

MSTEST0056 false-positive when custom TestClassAttribute overrides TestMethodAttribute #7073

@gao-artur

Description

@gao-artur
public class DerivedTestClassAttribute : TestClassAttribute
{
    public override TestMethodAttribute GetTestMethodAttribute(TestMethodAttribute testMethodAttribute)
    {
        return testMethodAttribute is DerivedTestMethodAttribute
            ? testMethodAttribute
            : new DerivedTestMethodAttribute(
                base.GetTestMethodAttribute(testMethodAttribute)!,
                testMethodAttribute.DeclaringFilePath,           <=== MSTEST0056 Use the 'DisplayName' property instead of passing a string argument to TestMethodAttribute
                testMethodAttribute.DeclaringLineNumber!.Value);
    }
}

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions