Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell mstest to ignore tests in a base class but not in subclasses?

I have a log parser that I am working on, and this log parser has an ILogStore interface that defines the base methods for any log record storage engine (in memory, in a database, etc..). The idea is that developers and users can add or remove log storage engines via the MEF plugin interface.

However, in order to confirm that a ILogStore implementation can correctly store, filter, and retrieve log entries I created a base class for unit/integration/API testing:

public class LogStoreBaseTests
{
    protected ILogStore _store;

    [TestMethod]
    public void Can_Store_And_Retrieve_Records() { }

    [TestMethod]
    public void Can_Filter_Records_By_Inclusive_Text() { }

    [TestMethod]
    public void Can_Filter_Records_By_Exclusive_Text() { }

    // etc...
}

I test my implemented tasks by doing something like:

[TestClass]
public class InMemoryLogStoreTests : LogStoreBaseTests
{
    [TestInitialize]
    public void Setup()
    {
        _store = new InMemoryLogStore();
    }
}

This works good except that MsTest notices that the methods in the base class have [TestMethod] but errors because the class doesn't have [TestClass], which it doesn't because it's not valid tests on it's own.

How can I tell MsTest to ignore the methods when not run from a subclass?

like image 518
KallDrexx Avatar asked Dec 05 '22 19:12

KallDrexx


1 Answers

Turns out MSTest has an [Ignore] Attribute. I placed that and the [TestClass] attribute on my base test, and it correctly ignores the test methods for the base tests while using the base test methods when run under a subclass

like image 166
KallDrexx Avatar answered Mar 22 '23 23:03

KallDrexx