【发布时间】:2011-11-22 23:37:44
【问题描述】:
我有一个正在开发的日志解析器,这个日志解析器有一个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...
}
我通过执行以下操作来测试我实施的任务:
[TestClass]
public class InMemoryLogStoreTests : LogStoreBaseTests
{
[TestInitialize]
public void Setup()
{
_store = new InMemoryLogStore();
}
}
这很好用,只是 MsTest 注意到基类中的方法有 [TestMethod] 但由于类没有 [TestClass] 而出错,因为它本身不是有效的测试。
如何告诉 MsTest 在不从子类运行时忽略这些方法?
【问题讨论】:
标签: c# inheritance mstest