Skip to content

Support abstract methods marked as tests #3798

@tannergooding

Description

@tannergooding

Feature Request

I would like to be able to do the following and have NUnit detect 4 tests.

public abstract class BaseClass
{
    [Test]
    public abstract void MyTest();

    [TestCase(1, 2)]
    public abstract void MyTestCase(int x, int y);

    // etc
}

public class DerivedClass1 : BaseClass
{
    public override void MyTest()
    {
        // Test Logic
    }

    public override void MyTestCase(int x, int y)
    {
        // Test Logic
    }
}

public class DerivedClass2 : BaseClass
{
    public override void MyTest()
    {
        // Test Logic
    }

    public override void MyTestCase(int x, int y)
    {
        // Test Logic
    }
}

Current Behavior

NUnit detects zero tests and doesn't even provide a warning that this is unsupported. The methods in DerivedClass1 and DerivedClass2 need to have the attributes replicated directly to be detected and run.

Alternatives

There are a number of alternatives for a user who is wanting this behavior. For example, they can have the methods in BaseClass be non abstract/virtual and instead call abstract methods.
This is mostly a convenience for the "simple" design when the user has a setup where the attributes are common and should be shared with all derived classes, but the backing logic needs to be customized.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions