Kal*_*exx 4 c# inheritance mstest
我有一个我正在处理的日志解析器,这个日志解析器有一个ILogStore接口,定义任何日志记录存储引擎的基本方法(在内存中,在数据库中等).这个想法是开发人员和用户可以通过MEF插件界面添加或删除日志存储引擎.
但是,为了确认ILogStore实现可以正确地存储,过滤和检索日志条目,我为单元/集成/ API测试创建了一个基类:
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...
}
Run Code Online (Sandbox Code Playgroud)
我通过执行以下操作来测试我执行的任务:
[TestClass]
public class InMemoryLogStoreTests : LogStoreBaseTests
{
[TestInitialize]
public void Setup()
{
_store = new InMemoryLogStore();
}
}
Run Code Online (Sandbox Code Playgroud)
这很好用,除了MsTest注意到基类中的方法有[TestMethod]错误,因为类没有[TestClass],但它没有,因为它不是有效的测试.
如何在不从子类运行时告诉MsTest忽略这些方法?