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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With