microsoft / testfx

MSTest framework and adapter
MIT License
697 stars 250 forks source link

MSTEST0011: report when class is `abstract` and inheritance is not specified #3224

Closed Evangelink closed 1 month ago

Evangelink commented 1 month ago

Summary

Report when an abstract class declares a member marked with [ClassCleanup] without specifying the inheritance behavior.

Background and Motivation

When an abstract class is declaring a [ClassCleanup] member without specifying the inheritance behavior, then this member will simply be ignored so we should flag the case.

Proposed Feature

Scenarios to flag:

[TestClass]
public abstract class BaseClass
{
    [ClassCleanup]
    public static void ClassCleanup()
    {
    }
}
public abstract class BaseClass
{
    [ClassCleanup]
    public static void ClassCleanup()
    {
    }
}

Valid scenario:

[TestClass]
public abstract class BaseClass
{
    [ClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.InheritanceBehavior.BeforeEachDerivedClass)]
    public static void ClassCleanup()
    {
    }
}

or

public abstract class BaseClass
{
    [ClassCleanup(Microsoft.VisualStudio.TestTools.UnitTesting.InheritanceBehavior.BeforeEachDerivedClass)]
    public static void ClassCleanup()
    {
    }
}